注入的context-param我已经定义在web.xml中的上下文参数Spring MVC的 - 从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
注解。但是,它似乎没有阅读它们。它始终是空
@Component 公共类TokBoxSettings {
@Value("${apikey}")
private String apikey;
@Value("${secretkey}")
private String secretkey;
我还增加了以下豆映射spring-servlet.xml
配置PropertyPlaceholder
<bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
</bean>
请让我知道我错过了
通常,bean定义和设置包含在'@ Configuration'注释类中。是否尝试将'@ Component'更改为'TokBoxSettings'的'@ Configuration'?这两种刻板印象在排序上可能有所不同。 – px5x2