In spring, you often use the @Value ("${property}") to take a value from the application.properties, you need to be aware of two points
- Classes that use @Value cannot instantiate objects using the New keyword and must be instantiated in a dependency injection manner
- You cannot use an explicit construction method
Otherwise, the value will not be taken. The workaround is as follows:
- Deleting an explicit construction method that requires content initialized with the constructor method can be used @postconstruct
@PostConstruct//Plus this annotation indicates that the method is called after the bean is initialized Private void init () {
Add your Content
}
- Using construction methods to inject
Public Long reportperiod) { this. reportperiod = reportperiod; + "1111111111111111111111111111111111111111"); }
Springboot @Value Get the value null, workaround