【发布时间】:2015-11-05 10:12:52
【问题描述】:
我已经在 web.xml 中定义了上下文参数
<context-param>
<param-name>apikey</param-name>
<param-value>45370652</param-value>
</context-param>
<context-param>
<param-name>secretkey</param-name>
<param-value>3eada72ef0ae12e15b138ae098c268c087f08ca8</param-value>
</context-param>
</web-app>
我在 bean 类的类和字段级别中启用了 @Component 和 @Value 注释。但是,它似乎没有阅读它们。它始终为空
@组件 公共类 TokBoxSettings {
@Value("${apikey}")
private String apikey;
@Value("${secretkey}")
private String secretkey;
我还将以下 bean 映射添加到 spring-servlet.xml 以配置 PropertyPlaceholder
<bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
</bean>
请告诉我我错过了什么
【问题讨论】:
-
一般bean定义和设置都包含在
@Configuration注解的类中。您是否尝试将TokBoxSettings的@Component更改为@Configuration?这两种刻板印象的顺序可能不同。
标签: java spring-mvc web.xml spring-annotations