小编Hwe*_*wen的帖子

无法解析字符串值中的占位符

我试图使用.properties文件中的属性,但它似乎不起作用.

这是我的代码:

@Service("ServiceFTP")
@Transactional
public class ServiceFTPImpl implements ServiceFTP {

@Value("${project.ftp.adresse}")
private String adresse;

@Value("${project.ftp.login}")
private String compte;

@Value("${project.ftp.password}")
private String motDePasse;

@Value("${project.ftp.root}")
private String ROOT;

[...]

}
Run Code Online (Sandbox Code Playgroud)

此类使用@Value注释来获取属性.它也被声明为Spring Service并链接到我的infraContext.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.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

<context:property-placeholder location="classpath:context-core.properties"/>

[...]

</beans>
Run Code Online (Sandbox Code Playgroud)

使用context:property-placeholder,我将此文件链接到我的context-core.properties文件:

project.ftp.adresse = localhost
project.ftp.login = anonymous
project.ftp.password =
project.ftp.root = /anonymous/
Run Code Online (Sandbox Code Playgroud)

这确实有道理,对吗?

但是当我尝试启动我的项目时,Tomcat抛出了这个异常:

    ERROR [context.ContextLoader.initWebApplicationContext()] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name …
Run Code Online (Sandbox Code Playgroud)

java spring

71
推荐指数
6
解决办法
24万
查看次数

标签 统计

java ×1

spring ×1