PropertyPlaceholderConfigurer 在 Maven 命令行中工作,但不能在 Eclipse 中工作?

发布于 2024-09-05 09:54:49 字数 1710 浏览 1 评论 0原文

我将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尴尬癌患者 2024-09-12 09:54:49
  • 过滤是否适用于 Eclipse 下的“常规”单元测试?
  • m2eclipse 是否配置为处理资源并测试资源更改时的资源:

alt text http://www .imagebanana.com/img/rwd919ek/screenshot_008.png

  • 关于您的集成测试(从 Maven 的角度来看)有什么特别值得一提的吗?
  • Does filtering work for a "regular" unit test under Eclipse?
  • Is m2eclipse configured to process resources and tests resources on resource changes:

alt text http://www.imagebanana.com/img/rwd919ek/screenshot_008.png

  • Is there anything particular to mention about your integration tests (from a Maven point of view)?
枯叶蝶 2024-09-12 09:54:49

您正在使用 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文