I'm sorry to ask the obvious, but how do you know that the @Value annotation is not working? One of the problems with the way Spring works is that the Bean pre-processing is carried out after construction of the Bean.
So if you were inspecting your Bean in the constructor with a debugger, you will not see the fields being set. You can add a method in your Bean called, say, audit() and annotate it with @PostConstruct and if you put a log statement in there, put a breakpoint on it, you should see the fields with their @Value values.
If you do that and you still do not see your @Value fields, then you might not even has scanned the Bean. A class that you think implements a Bean is still a Java class, which can be instantiated and will have its fields assigned null, if it is not being pre-processed.
To make sure your Beans are being scanned, the classes should have at least the @Component and you need to add the package of the classes to the @ComponentScan.
@ComponentScan(basePackages = { "com.example.springboot", "org.bilbo.baggins" })
If you don't have the source to the main() method is, which is where you can usually find @ComponentScan, then you can add a @Configuration class in the same package and add a @ComponentScan to that.
In this example, I have the @ComponentScan as a commented-out line in the wrong place (it should replace @ImportResources).
package com.example.springboot;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
// @ComponentScan(basePackages = { "com.example.springboot", "org.bilbo.baggins" })
@Configuration
@ImportResource({"classpath*:applicationContext.xml"})
public class Configurer {
}
I did that, to show how to use an XML file: applicationContext.xml. This contains a component-scan and creates a Bean.
(Note: only one package is stated to be scanned, component-scan seems to accumulate.)
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/sc
hema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/
beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema
/context/spring-context.xsd">
<context:annotation-config />
<context:component-scan base-package="org.bilbo.baggins" />
<bean id="applicationProperties"
class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="location" value="classpath:application.properties" />
</bean>
</beans>
It is useful to build a bean in the XML file, so that you list it and demonstrate that you have loaded the XML file. You can list the beans using the method String[] beanNames = ctx.getBeanDefinitionNames();