简体   繁体   English

spring-social-twitter,@ Value不是接线属性

[英]spring-social-twitter, @Value not wiring attribute

While extending Spring Twitter Social, I'm using application-test.properties and I can't get @Value to autowire the properties into some fields. 在扩展Spring Twitter Social时,我使用的是application-test.properties ,但无法获取@Value将属性自动关联到某些字段中。

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: src / test / resources中的application-test.properties

# 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. 但是,在我的spring-social-twitter扩展程序(针对Spring Social Twitter提到的一个Im)中,这些值从未绑定。

I have also tried to get the parameters into the application.properties , no luck too... 我也尝试将参数放入application.properties中 ,也没有运气...

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. 确保该文件存在于类路径中,并且具有@Value批注的类由Spring初始化。

The class which is using @Value annotation seems to be not getting initialised by the spring. 使用@Value批注的类似乎在春季之前尚未初始化。 If the spring initialises the class, it should pick up the values with @Value annotation. 如果spring初始化了该类,则应使用@Value注释拾取值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM