Spring 弹簧罐';找不到属性
我在应用程序上下文中有以下定义:Spring 弹簧罐';找不到属性,spring,Spring,我在应用程序上下文中有以下定义: <beans xmlns:context="http://www.springframework.org/schema/context" ... http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd <context:property-placeholder
<beans xmlns:context="http://www.springframework.org/schema/context"
...
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
<context:property-placeholder location="classpath:propfile.properties"/>
由于它是maven项目的一部分,我找到了如下文件:
-src/main/java
-src/main/resources
--propfile.properties
现在,在我的组件中:
@WebService
@Component
public class MyService{
@Value("#{parallelism}")
private Integer parallelism;
....
}
在初始化阶段,它给我
在类型为的对象上找不到字段或属性“parallelism”
'org.springframework.beans.factory.config.BeanExpressionContext
为什么??此外,在web应用程序环境中使用属性占位符是否正确?或者是否有其他方法设置属性?请尝试按以下方式更改配置文件:
<bean id="propfile" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath*:propfile.properties</value>
</list>
</property>
</bean>
此外,您还可以按如下方式访问完整的属性文件:
@Component
public class MyService{
@Resource(name="propfile")
private Properties propfile;
....
}
属性占位符是否与组件扫描位于同一spring配置文件中?它是否在另一个spring配置文件中,是否要导入它?同时#前缀引用spring表达式语言查询,如果引用的是属性文件,则应使用$prefix。
@WebService
@Component
public class MyService{
@Value("${parallelism}")
private Integer parallelism;
....
}
@Component
public class MyService{
@Resource(name="propfile")
private Properties propfile;
....
}