希望你能提供帮助。如果解决方案非常明显,那么我的Spring知识非常局限于道歉。
以下是相关文件的内容:
应用context.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd">
<context:annotation-config />
<util:properties id="messageConfig" location="classpath:customMessages.properties"/>
</beans>
/src/main/resources/customMessages.properties:
sms.message=Test
Java类:
@Controller
public class ApiRestController implements ApiRest {
@Value("#{messageConfig['sms.message']}")
private String smsMessage;
public final void setSmsMessage (String smsMessage)
{
this.smsMessage = smsMessage;
}
...
}
但是,在引用&#39; smsMessage&#39;在Java类的其他地方变量,值为NULL。任何想法我可能会失踪?任何指针都会非常感激。
答案 0 :(得分:0)
添加
<context:component-scan base-package="spring-controllers-package"/>
到 application-context.xml