views:

111

answers:

2

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.

A: 

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?

khmarbaise
Yes -- I am using Maven 2 (2.2.1). The test is a true "integration" test. I call it a "unit" test when running it inside Eclipse only because that is the only term Eclipses uses (it doesn't differentiate). "Astonished" is a great word for this. It is extremely disturbing to see tooling behave in this way. If I can't trust Eclipse vs Maven command line, then that is really bad.
HDave
+2  A: 
  • Does filtering work for a "regular" unit test under Eclipse?
  • Is m2eclipse configured to process resources and tests resources on resource changes:

alt text

  • Is there anything particular to mention about your integration tests (from a Maven point of view)?
Pascal Thivent
Yes -- regular Maven filtering works under Eclipse (and will be my temporary work-around). My m2Eclipse project settings is exactly like your screen shot, except I don't have the WTP configurator.I have another module of this project that uses a PPC and it works, so it must be something about this module. Also, I am using the default value of false for ignoreUnresolvablePlaceholders, so you'd think the PPC would throw an exception, not hand back an bad string.
HDave
@HDave Actually, this looks more like a "Spring issue" than a Maven issue. I really wonder what is "special" with the integration test. If you run the Maven build from Eclipse before to run you test, does the result differ?
Pascal Thivent
@Pascal - After many hours of research and debugging here is what I found. The Maven filtering worked fine for my applicationContext.xml file because it is a Test Resource. The Maven filtering is broken on database.properties (I think) because it is a "Resource".So the culprit is not PPC, but m2eclipe and that fact that for some unknown reason it is not filtering my regular resource the way the command line does. But how/why could it be different?
HDave
@Pascal -- After even more hours of study I've determined that when you select a Junit debug or run configuration in Eclipse it seems to have almost no relationship with m2eclipse. Classes are missing, resources aren't copied, etc. The only way it reliably works is to do a full 'mvn verify' (or test/install) first. Then it seems to work fine.
HDave