PropertyPlaceholderConfigurer 在 Maven 命令行中工作,但不能在 Eclipse 中工作?
我将 Eclipse 配置为使用外部 Maven 实例。尽管如此,我有一个集成测试,它在命令行中运行良好,但在 Eclipse 中失败。该错误是 Spring 应用程序上下文 bean 类错误:
Cannot convert value of type [java.lang.String] to required type
罪魁祸首是使用 PropertyPlaceholderConfigurer 设置属性值的 bean。
<!-- property settings for non-JNDI database connections -->
<bean id="placeholderConfigUuid" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="location" value="classpath:database.properties" />
<property name="placeholderPrefix" value="$DS{" />
</bean>
我知道哪个 bean 失败了,因为它出现在堆栈跟踪中,并且因为当我用静态值替换 $DS{hibernate.dialect} 时它可以工作。
编辑:这里是使用属性值的地方:
<bean id="myTestLocalEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="myapp-core" />
.......ommitted for brevity.......
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<!-- The following use the PropertyPlaceholderConfigurer but it doesn't work in Eclipse -->
<property name="database" value="$DS{hibernate.database}" />
<property name="databasePlatform" value="$DS{hibernate.dialect}" />
</bean>
</property>
</bean>
我有两个问题:
1)由于 M2Eclipse 使用与命令行相同的 Maven 设置,为什么一个可以工作,另一个则失败? 2)如何解决这个问题?我真的很喜欢从 Eclipse 中按需运行单个 jUnit 测试的能力。
I have Eclipse configured to use an external maven instance. Nonetheless I have an integration test that runs fine from the command line, but fails from within Eclipse. The error is a class Spring application context bean error:
Cannot convert value of type [java.lang.String] to required type
The culprit it a bean that sets property values using a PropertyPlaceholderConfigurer.
<!-- property settings for non-JNDI database connections -->
<bean id="placeholderConfigUuid" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="location" value="classpath:database.properties" />
<property name="placeholderPrefix" value="$DS{" />
</bean>
I know which bean is failing because it appears in the stack trace and because when I replace the $DS{hibernate.dialect} with a static value it works.
EDIT: Here is where the property values are used:
<bean id="myTestLocalEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="myapp-core" />
.......ommitted for brevity.......
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<!-- The following use the PropertyPlaceholderConfigurer but it doesn't work in Eclipse -->
<property name="database" value="$DS{hibernate.database}" />
<property name="databasePlatform" value="$DS{hibernate.dialect}" />
</bean>
</property>
</bean>
I have two questions:
1) Since M2Eclipse is using the same Maven setup as the command line, why does one work and the other fail?
2) How to fix this? I really like the ability to run a single jUnit test from within Eclipse on demand.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
alt text http://www .imagebanana.com/img/rwd919ek/screenshot_008.png
alt text http://www.imagebanana.com/img/rwd919ek/screenshot_008.png
您正在使用 M2Eclipse(最新版本?)您正在 Eclipse 中使用 Maven 3,但我假设您在命令行上使用 Maven 2(2.2.1?)...另一方面,您是说您的“集成测试”正在命令行上运行(构建环境等),但您想从 Eclipse 中运行“单元测试”...单元测试与集成测试不同...我并不感到惊讶您的集成测试在 Eclipse 中不起作用...如果我们看到所使用的 POM 和代码,也许我们可以说更多?
You are using M2Eclipse (up-to-date release?) you are using Maven 3 inside Eclipse, but i assume you are using Maven 2 (2.2.1?) on command line...On the other side you are saying that your "Integration test" is running on command line (build an environment etc.) but you would like to run "Unit Test" from within Eclipse...A Unit Test is different from an integration test...and i'm not astonished that you integration test does not work from Eclipse...May be we can say more if we see the POM's which are used and the code?