1,在springmvc的controller中注解属性
public class TranOrderController extends BaseController {
@Value("${filePath}")
private String filePath;
public void down(){
logger.info(filePath); //总是打印${filePath}
}
}
原因及解决办法:
web.xml配置
//这个spring的配置
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:META-INF/spring/spring-mybatis.xml</param-value>
</context-param>
//这个是DispatcherServlet中的配置
<servlet>
<servlet-name>found</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:META-INF/spring/found-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>found</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
在这2个xml文件中要分别加入加载properties文件的配置
spring-mybatis.xml的
<bean id="sourcePropertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:dubbo.properties</value>
<value>classpath:mq.properties</value>
<value>classpath:console.properties</value> //这个是我要用到Valuede
</list>
</property>
</bean>
found-servlet.xml的,这段配置开始的时候是没有的,加上就没问题了
<bean id="sourcePropertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:console.properties</value> //只加了其中要用到的 //这个是我要用到Valuede
</list>
</property>
</bean>