java - Issue with @Value and application.properties since moving to Spring Boot 1.1.4.RELEASE -


I have a problem because I have moved to version 1.1.4 of Spring Boot.

My values ​​are annotated with the value @, despite being present in the application, prices are not being populated yet. Properties Before I was using Spring Boot @ version 1.0.2, and it was working fine.

All this started after the upgrade, and I did not make any code changes.

Sample Application.Java Package org.sample; Import org.springframework.beans.factory.annotation.Value; Import org.springframework.boot.SpringApplication; Import org.springframework.boot.autoconfigure.EnableAutoConfiguration; Import org.springframework.context.annotation.ComponentScan; Import org.springframework.context.annotation.configuration; Import org.springframework.context.annotation.PropertySource; Import organization Source: @Configuration @ComponentScan @EnableAutoConfiguration @PropertySource (value = "classpath: application.properties") public class SampleApplication {private static Logger logger = LoggerFactory .getLogger (TaskManagerApplication.class); @well ("$ {org.sample.sampleProperty}") Private static string sample property; Public static zero main (string [] args) {SpringApplication.run (SampleApplication.class, args); System.out.print ("Sample Application Started:" + Sample Property); } @ Bean public static property Source placeholder Configorr Proprtijis Plesdhark Configurr () {new Proprtisait placeholder Configurr (); }}

Aplikeshnkproprtij

  Springkdtsurskuarel: whereas: Mickle: //l27k0k0kl: 3306 / Meedb Springkdtsurskugrnam : root spring.datasource.password: root spring.datasource.driverClassName: com.mysql.jdbc.Driver spring.jpa.show- SQL truth #disable DDL- Auto: once the table # spring.jpa.hibernate have went created make .ddl- Auto: / temp / UserPhotos / # server port server.port = 8081   

I: org.sample.sampleProperty make = this is a sample property photos.upload.dir = C Has added property source placeholder configuration bean and even property site placeholder configurator But the problem persists even then.

Has anyone experienced this? Or is there a new way to load properties files?

Please note that my DB connection and server port are being read properly because my application can be connected to DB and I have to access it through the specified port. The sampleProperty variable is still null .

  1. @value is not made, application. Properties
  2. To work on properties, these are automatically available without specifying @PropertySource .
  3. Instead of printing the property in the main method, you should do this after creating the bean, for example @PostConstruct

    Example:

      package demo; Import org.springframework.beans.factory.annotation.Value; Import org.springframework.boot.SpringApplication; Import org.springframework.boot.autoconfigure.EnableAutoConfiguration; Import org.springframework.context.annotation.ComponentScan; Import org.springframework.context.annotation.configuration; Import javax.annotation.PostConstruct; @Configuration @ComponentScan @EnableAutoConfiguration Public Class Application {@Value ("$ {org.sample.sampleProperty}") Private String Sample Property; Public static zero main (string [] args) {SpringApplication.run (application.class, args); } @PostConstruct Public Zero Post () {System.out.print ("Sample Application Started:" + Sample Property); }}    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -