我有一个使用 spring 的 java 应用程序,我需要对其进行测试。我正在使用 Jython 2.5.2 和 Eclipse 上安装的 Springpython 1.3.0RC。Java 应用程序使用属性文件 prop.properties 并使用如下注释:
@Value("${csvdatafetcher.filename:input.csv}")
属性文件是:core.filedatafetcher.filename=test.csv
我正在尝试调用应用程序:
from springpython.context import ApplicationContext
from springpython.config import SpringJavaConfig
ctx = ApplicationContext(SpringJavaConfig("javaBeans.xml"))
service = ctx.get_object("csvDataFetcher")
使用弹簧 xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans">
....
<bean id="props" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:classpath:prop.properties</value>
</property>
</bean>
<bean id="csvDataFetcher" class="com.framework.fetchers.CsvFileDataFetcher" />
</beans>
它给了我错误:
Traceback (most recent call last):
File "/home/nir/.eclipse/org.eclipse.platform_3.6.1_185596441/plugins/org.python.pydev.debug_2.2.4.2011110216/pysrc/pydevd.py", line 1307, in <module>
debugger.run(setup['file'], None, None)
File "/usr/share/jython2.5.2/Lib/site-packages/springpython-1.3.0.RC1-py2.5.egg/springpython/container/__init__.py", line 80, in get_object
comp = self._create_object(object_def)
File "/usr/share/jython2.5.2/Lib/site-packages/springpython-1.3.0.RC1-py2.5.egg/springpython/container/__init__.py", line 132, in _create_object
[prop.set_value(obj, self) for prop in object_def.props if hasattr(prop, "set_value")]
File "/usr/share/jython2.5.2/Lib/site-packages/springpython-1.3.0.RC1-py2.5.egg/springpython/config/_config_base.py", line 149, in set_value
setattr(obj, self.name, self.value)
TypeError: can't convert 'classpath:spring-config-test.xml' to org.springframework.core.io.Resource;
或使用(而不是 bean id="props"...):
<context:property-placeholder location="classpath:prop.properties" />
这给了我错误:
Traceback (most recent call last):
File "/home/nir/.eclipse/org.eclipse.platform_3.6.1_185596441/plugins/org.python.pydev.debug_2.2.4.2011110216/pysrc/pydevd.py", line 1307, in <module>
debugger.run(setup['file'], None, None)
File "/usr/share/jython2.5.2/Lib/site-packages/springpython-1.3.0.RC1-py2.5.egg/springpython/container/__init__.py", line 128, in _create_object
obj = object_def.factory.create_object(self._get_constructors_pos(object_def),
File "/usr/share/jython2.5.2/Lib/site-packages/springpython-1.3.0.RC1-py2.5.egg/springpython/factory/__init__.py", line 31, in create_object
parts = self.module_and_class.split(".")
AttributeError: 'NoneType' object has no attribute 'split'
- 如何将java属性占位符转换为python spring?
- 如何注入连接到注解@Value 的属性?
谢谢,