While extending Spring Twitter Social, I'm using application-test.properties and I can't get @Value to autowire the properties into some fields.
DETAILS OF THE ISSUE
@Value("${spring.social.twitter.hosts.ads-api}")
private String baseUrlApiAds;
@Value("${spring.social.twitter.hosts.standard-api}")
private String baseUrlApiStandard;
application-test.properties in src/test/resources:
# spring-social-twitter
spring.social.twitter.hosts.standard-api : https://api.twitter.com/1.1/
spring.social.twitter.hosts.ads-api : https://ads-api-sandbox.twitter.com/0/
However, inside my spring-social-twitter extension (the one Im mentioned for Spring Social Twitter), the values are never bound.
I have also tried to get the parameters into the application.properties , no luck too...
This is the top of the declaration of my integration test:
@RunWith(SpringJUnit4ClassRunner.class)
@WebIntegrationTest("server.port:9003")
@SpringApplicationConfiguration(classes = { Application.class, IntegrationConfig.class })
@ActiveProfiles(IntegrationConfig.PROFILE_TEST)
public abstract class IntegrationTest {
}
Could anybody give me a hand?
Above integration test, can you please try putting this annotation:
@PropertySource(value = "classpath:application-test.properties")
Mke sure that the file is present in classpath, and the class which has @Value annotations is initialised by the spring.
The class which is using @Value
annotation seems to be not getting initialised by the spring. If the spring initialises the class, it should pick up the values with @Value
annotation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.