SpringToolSuite, Eclipse and Standalone Maven and classpath

335 views
Skip to first unread message

Pilgrim, Peter

unread,
May 18, 2010, 12:17:15 PM5/18/10
to jav...@googlegroups.com

Hello

 

I have just spent 3 hours to trying to get a unit test to run inside SpringTool Suite 2.3.2

 

 

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration(locations = {

            "/META-INF/application-context-col-fx-ws-test.xml",

            "/META-INF/application-context-col-fx-ws.xml" })

public class ColFxServiceEndpointTest {

      /* . . . */

}

 

The unit test works outside of the IDE on the command line, I can execute “mvn clean test” and then Maven completes successfully.

However trying to run the same thing in Eclipse, or rather STS, produces

 

Ijava.lang.IllegalStateException: Failed to load ApplicationContext

            at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:308)

            at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)

            at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)

            at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:333)

            at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:220)

            at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:301)

            at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

            at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:303)

            at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)

            at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)

==/////==

Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:META-INF/application-context-col-fx-ws.xml]

Offending resource: class path resource [META-INF/application-context-col-fx-ws-test.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:META-INF/application-context-col-fx-services.xml]

Offending resource: class path resource [META-INF/application-context-col-fx-ws.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [META-INF/application-context-col-fx-services.xml]; nested exception is java.io.FileNotFoundException: class path resource [META-INF/application-context-col-fx-services.xml] cannot be opened because it does not exist

 

WTF, man?!

 

At first, I thought was a simple problem like it was M2Eclipse plugin, check: the plugin is indeed enabled, Maven dependencies are preferred option. Next, I looked at the POM.xml, check: I see we have JUnit 4.7 listed. I looked at the build class path in Eclipse, check: all JAR appear to be. Finally, I thought it was the resource path was wrong, so I tried “classpath:/META-INF/application-context-col-fs-ws.xml”. And finally, I can the resources are in fact in target\classes\META-INF and target\test-classes\META-INF respectively.

 

Anyone know what is going on? I looked at the Spring Forum and this sodding configuration-error-thing with Spring and Unit Testing seems to be popular! There are no obvious solution that explain, however, what is going between Maven and Eclipse worlds.

 

Is this another example of Spring AOP weirdness?

 

 

 

--

Peter Pilgrim | E-Channel Services, Technical Lead, eBusiness

Lloyds Banking Group | Wholesale Markets & Treasury IT

33 Old Broad Street, London, EC2N 1HZ, UK

' +44 (0)207 158 6135 | ( +44 (0)1234 567 8901

+ peter....@lloydsbanking.com

: www.lloydsbankinggroup.com

 

 



This e-mail is private and confidential and may contain privileged material. If you have received this e-mail in error, please notify the sender and delete it immediately. You must not copy, distribute, disclose or use any of the information in it or any attachments.

Lloyds Banking Group plc. Registered Office: The Mound, Edinburgh EH1 1YZ. Registered in Scotland, number 95000. Telephone: 0131 225 4555.

Lloyds TSB Bank plc. Registered Office: 25 Gresham Street, London EC2V 7HN. Registered in England and Wales, number 2065. Telephone: 020 7626 1500.

Lloyds TSB Scotland plc. Registered Office: Henry Duncan House, 120 George Street, Edinburgh EH2 4LH. Registered in Scotland, number 95237. Telephone: 0131 225 4555.

Cheltenham & Gloucester plc. Registered Office: Barnett Way, Gloucester GL4 3RL. Registered in England and Wales, number 2299428. Telephone: 01452 372372.

Cheltenham & Gloucester Savings is a division of Lloyds TSB Bank plc.
Lloyds TSB Bank plc, Lloyds TSB Scotland plc and Cheltenham & Gloucester plc are authorised and regulated by the Financial Services Authority.

Telephone calls may be monitored or recorded.

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________

--
You received this message because you are subscribed to the Google Groups "JAVAWUG" group.
To post to this group, send email to jav...@googlegroups.com.
To unsubscribe from this group, send email to javawug+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/javawug?hl=en.

Pilgrim, Peter

unread,
May 18, 2010, 1:07:23 PM5/18/10
to jav...@googlegroups.com

Sorry if I spammed the list. It has been one of those days in the office.

Tomasz Wrobel

unread,
May 18, 2010, 1:08:49 PM5/18/10
to jav...@googlegroups.com
To double check you could:
1) check in your project's properties, Java Build Path, if all 'Output
folder's point to ../target/classes
2) try to clean your project ('Project' -> 'Clean...' top menu option)
Tomek

Tomasz Wrobel

unread,
May 18, 2010, 1:21:14 PM5/18/10
to jav...@googlegroups.com
Just spotted:
The message is also about META-INF/application-context-col-fx-services.xml
not only about
"/META-INF/application-context-col-fx-ws-test.xml",
"/META-INF/application-context-col-fx-ws.xml"

Is it imported in mentioned files?

On Tue, May 18, 2010 at 5:17 PM, Pilgrim, Peter
<peter....@lloydsbanking.com> wrote:

Peter Pilgrim

unread,
May 18, 2010, 1:36:37 PM5/18/10
to jav...@googlegroups.com
On 18 May 2010 18:08, Tomasz Wrobel <twr....@gmail.com> wrote:

Thanks Tomasz

> To double check you could:
> 1) check in your project's properties, Java Build Path, if all 'Output
> folder's point to ../target/classes

Check. They go to target/classes and target/test-classes respectively

> 2) try to clean your project ('Project' -> 'Clean...' top menu option)
> Tomek
>
I cleaned that specific project again and it looked at the Maven
Console output/ in STS. It appears that our department firmwide Nexus
server is missing a maven-resources-plugin:2.4.1:jar !

This could be one of the reason. This is a typical issue when a team
maintains a firm wide Nexus artifact server. So much time is spent
grabbing artifacts from the Internet and loading them on the server.

I will fixed this missing maven-resources-plugin.jar 2moro. Feierabend!



--
Peter A. Pilgrim
JavaFX / Java EE Software Development / Design / ScrumMaster
(``Java Champion #91`'')

**** See you at Martin Odersky's London Scala Workshop 2010 ****

:: http://audio.fm/profile/peter_pilgrim ::
:: http://jroller.com/peter_pilgrim ::
:: http://jroller.com/javawug ::
:: https://java-champions.dev.java.net/ ::
:: http://www.linkedin.com/in/peterpilgrim2000 ::
:: http://www.facebook.com/profile.php?id=570597454 ::
:: http://twitter.com/peter_pilgrim ::
:: http://twitter.com/javawugcom ::
:: A Sun Certified Enterprise Architect for Java EE 5 platform ::

Peter Pilgrim

unread,
May 18, 2010, 1:40:40 PM5/18/10
to jav...@googlegroups.com
On 18 May 2010 18:21, Tomasz Wrobel <twr....@gmail.com> wrote:
> Just spotted:
> The message is also about META-INF/application-context-col-fx-services.xml
> not only about
> "/META-INF/application-context-col-fx-ws-test.xml",
> "/META-INF/application-context-col-fx-ws.xml"
>
> Is it imported in mentioned files?

Tomasz

I don't understand what you mean.




--
Peter A. Pilgrim
JavaFX / Java EE Software Development / Design / ScrumMaster
(``Java Champion #91`'')

**** See you at Martin Odersky's London Scala Workshop 2010 ****

:: http://audio.fm/profile/peter_pilgrim ::
:: http://jroller.com/peter_pilgrim ::
:: http://jroller.com/javawug ::
:: https://java-champions.dev.java.net/ ::
:: http://www.linkedin.com/in/peterpilgrim2000 ::
:: http://www.facebook.com/profile.php?id=570597454 ::
:: http://twitter.com/peter_pilgrim ::
:: http://twitter.com/javawugcom ::
:: A Sun Certified Enterprise Architect for Java EE 5 platform ::

Richard Gomes

unread,
May 18, 2010, 5:36:10 PM5/18/10
to jav...@googlegroups.com
Hi Peter,

Sorry if not related and/or absolutely irrelevant, but anyway:

I have problems like this all the time. I mean, not exactly like this
but differences when running inside Eclipse of via mvn command line.

There's a difference how tests are performed inside Eclipse and from the
command line, specially in regards to multithreading. Most tests pass
inside Eclipse but eventually fail from the command line.
Eventually this is the other way round.

First step is isolate which test case is failing and then isolate which
step inside a test case is probably guilty for the failure. After that,
try to identify if there are racing conditions related to those lines of
code. Unfortunately, I'm not aware of tools or better techniques: the
only technique I'm aware of is detailed analysis of racing conditions.

I hope it helps.

Cheers

Richard Gomes



On 18/05/10 18:40, Peter Pilgrim wrote:
> On 18 May 2010 18:21, Tomasz Wrobel <twr....@gmail.com> wrote:
>> Just spotted:
>> The message is also about META-INF/application-context-col-fx-services.xml
>> not only about
>> "/META-INF/application-context-col-fx-ws-test.xml",
>> "/META-INF/application-context-col-fx-ws.xml"
>>
>> Is it imported in mentioned files?
>
> Tomasz
>
> I don't understand what you mean.
>
>
>
>

--

Peter Pilgrim

unread,
May 19, 2010, 2:25:34 AM5/19/10
to jav...@googlegroups.com
On 18 May 2010 22:36, Richard Gomes <rgome...@googlemail.com> wrote:
> Hi Peter,
>
> Sorry if not related and/or absolutely irrelevant, but anyway:
>
> I have problems like this all the time. I mean, not exactly like this
> but differences when running inside Eclipse of via mvn command line.
>

Yet if you are practicising any sort of agile, it has to be the mvn
that wins, because
you are relying on Hudson or another CI server of course.

> There's a difference how tests are performed inside Eclipse and from the
> command line, specially in regards to multithreading. Most tests pass
> inside Eclipse but eventually fail from the command line.
> Eventually this is the other way round.
>

I have noticed that Eclipse java compiler behaves quite differently in
rare situations in comparison
to Sun^^^ / Oracle JDK !

> First step is isolate which test case is failing and then isolate which
> step inside a test case is probably guilty for the failure. After that,
> try to identify if there are racing conditions related to those lines of
> code. Unfortunately, I'm not aware of tools or better techniques: the
> only technique I'm aware of is detailed analysis of racing conditions.

There is only one junit test class with a single JUnit @Test annotated method.
There are no threads at the moment as this is almost a green project.

There are however multi-modules as there are in a typical Java EE maven project.
Thanks

>
> I hope it helps.
>
> Cheers
>
> Richard Gomes
>
>
>
> On 18/05/10 18:40, Peter Pilgrim wrote:
>> On 18 May 2010 18:21, Tomasz Wrobel <twr....@gmail.com> wrote:
>>> Just spotted:
>>> The message is also about META-INF/application-context-col-fx-services.xml
>>> not only about
>>> "/META-INF/application-context-col-fx-ws-test.xml",
>>> "/META-INF/application-context-col-fx-ws.xml"
>>>
>>> Is it imported in mentioned files?
>>
>> Tomasz
>>
>> I don't understand what you mean.
>>
>>
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups "JAVAWUG" group.
> To post to this group, send email to jav...@googlegroups.com.
> To unsubscribe from this group, send email to javawug+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/javawug?hl=en.
>
>



--
Peter A. Pilgrim
JavaFX / Java EE Software Development / Design / Architecture
(``Java Champion #91`'')

**** See you at Martin Odersky's London Scala Workshop 2010 ****

:: http://audio.fm/profile/peter_pilgrim ::
:: http://jroller.com/peter_pilgrim ::
:: http://jroller.com/javawug ::
:: https://java-champions.dev.java.net/ ::
:: http://www.linkedin.com/in/peterpilgrim2000 ::
:: http://www.facebook.com/profile.php?id=570597454 ::
:: http://twitter.com/peter_pilgrim ::
:: http://twitter.com/javawugcom ::
:: A Sun Certified Enterprise Architect for Java EE 5 platform ::

Pilgrim, Peter

unread,
May 19, 2010, 6:19:32 AM5/19/10
to jav...@googlegroups.com


It was caused by inconsistent JUnit versions 4.4 (parent col-fx) versus
4.7 (col-fx-ws)

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
</dependencies>

So we have a Maven master parent Project ``Col-fx'' and a sub module
called ``col-fx-ws'', one declared JUnit 4.4 and the other JUnit 4.7. I
apologise humble Eclipse STS it was not your fault at all, it was ours.
We have to get better at organising Maven dependencies here ...(sigh)

Also we fixed in the meantime class path references to make sure if we
put resources in src/main/resources etc then the Maven commandline and
the Maven embedder (Eclipse STS) will not ever get confused by denoting
the protocol to read from the classpath and from the root package/folder
i.e "classpath:/foo-app-context.xml" replace the relative resource path
name "foo-app-context.xml"



--
Peter Pilgrim | E-Channel Services, Technical Lead, eBusiness
Lloyds Banking Group | Wholesale Markets & Treasury IT
33 Old Broad Street, London, EC2N 1HZ, UK
' +44 (0)207 158 6135 | ( +44 (0)1234 567 8901
+ peter....@lloydsbanking.com
: www.lloydsbankinggroup.com


This e-mail is private and confidential and may contain privileged material. If you have received this e-mail in error, please notify the sender and delete it immediately. You must not copy, distribute, disclose or use any of the information in it or any attachments.

Lloyds Banking Group plc. Registered Office: The Mound, Edinburgh EH1 1YZ. Registered in Scotland, number 95000. Telephone: 0131 225 4555.

Lloyds TSB Bank plc. Registered Office: 25 Gresham Street, London EC2V 7HN. Registered in England and Wales, number 2065. Telephone: 020 7626 1500.

Lloyds TSB Scotland plc. Registered Office: Henry Duncan House, 120 George Street, Edinburgh EH2 4LH. Registered in Scotland, number 95237. Telephone: 0131 225 4555.

Cheltenham & Gloucester plc. Registered Office: Barnett Way, Gloucester GL4 3RL. Registered in England and Wales, number 2299428. Telephone: 01452 372372.

Cheltenham & Gloucester Savings is a division of Lloyds TSB Bank plc.
Lloyds TSB Bank plc, Lloyds TSB Scotland plc and Cheltenham & Gloucester plc are authorised and regulated by the Financial Services Authority.

Telephone calls may be monitored or recorded.


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________

Reply all
Reply to author
Forward
0 new messages