我的流程类:
@Configurable("checkLicense")
public class CheckLicense {
String licensePath ;
@Value("${licenseKeyNotFound}")
String licenseKeyNotFound;
public boolean checkIn(String licensepath) {
System.out.println("hello "+licenseKeyNotFound);
licensePath = licensepath;
return checkIn();
}
}
我的ApplicationContext.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean class="com.smart.applicationlicense.CheckLicense"
scope="prototype">
</bean>
</beans>
这是我的属性文件。
licenseKeyNotFound = License File Corrupted
这是我的 servlet xml。
<context:property-placeholder location="conf/LicenseSettings.properties"
order="2" ignore-unresolvable="true" />
尽管我使用了 @Configurable
注释以及属性 Autowire.BY_NAME、Autowire.BY_TYPE
,但我无法从属性文件启动 licenseKeyNotFound
变量。
我能够从 Controller 启动变量,但不能从声明为 @Configurable
的类启动该变量。
任何人都可以让我知道我缺少什么或我的代码有什么问题吗?
如果我的代码需要某些内容,请告诉我。
最佳答案
试试这个:
在你的 spring xml 中:
<context:property-placeholder location="classpath:your.properties" />
<context:load-time-weaver />
关于java - 无法使用@Value注释启动变量,spring,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14477078/