java - 无法使用@Value注释启动变量,spring

标签 java spring spring-mvc

我的流程类:

@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/

相关文章:

java - Spring Batch,作者中的更新语句?抛出 IllegalArgumentException

java - 通过模块连接外部Java程序与Apache

java.lang.IllegalArgumentException : Unsupported class file major version 59

spring - 不允许 HTTP 405 - Spring Boot + Spring Security

java - Spring Security 自定义身份验证要求

Spring 3.0 MVC MVC :view-controller tag

java - 如何移动 SD 卡中的 Realm 文件?

java - ie 6下载servlet问题

spring - request.getServletPath() 从 Spring MVC 返回 null

java - Spring 启动: Bypass OncePerRequestFilter filters