spring maven项目:在autowire属性时导致BeanCreationException

时间:2017-06-15 15:26:12

标签: java spring maven properties

的application.xml              

<bean id="setting" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="locations">
        <list>
            <value>classpath:ftp/ftp.properties</value>
            <value>classpath:im/im.properties</value>
        </list>
    </property>

    <property name="fileEncoding" value="UTF-8"></property>
</bean>

属性

ftp_url = 192.168.1.136
ftp_port = 21
ftp_name = aloha
ftp_password = 123456

的java

@Component("ftpConfigProperty")
public class FtpConfigProperty {
    @Value("#{setting.ftp_url}")
    private String url;

    @Value("#{setting.ftp_port}")
    private String port;

    @Value("#{setting.ftp_name}")
    private String name;

    @Value("#{setting.ftp_password}")
    private String password;

    //getter & setter
}

@Component("ftpUtil")
public class FtpUtil {
    @Autowired
    private FtpConfigProperty ftpConfigProperty;
}

异常

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ftpConfigProperty': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.String com.aloha.app.common.file.FtpConfigProperty.url; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Property or field 'setting' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public?

我运行单元测试然后项目抛出此异常,但是当我跳过测试并编译这个maven项目时它没有出现。请帮助,非常感谢。

0 个答案:

没有答案