So I ran into an issue today that has been detailed at in the Spring forums that at first glance, looked identical to my issue. But this was in fact not my issue.

First off, when I was using acegi, I declared an applicationContext-test.xml that myTestNG would instanciate. I then would import my other applicationContext*.xml’s that I thought I would need. Now this did not cause an issue in acegi:

But when I moved to Spring Security 2.0.2, I started getting this error:

Offending resource: class path resource [applicationContext-test.xml];
nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Duplicate  detected.
Offending resource:
file [C:\opt\projects\baselogic\common-services\webapp-services\web\target\test-classes\WEB-INF\applicationContext-security.xml]
    at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(

When I removed the I got the same error in the section just as the spring thread above.

The thing that helped me to solve this, and was a strange indicator, was that when I ran this stand alone “mvn -Dcargo.wait=true cargo:start” or “mvn tomcat:run-war” the application would start, and function as expected. So I was confused as everything worked before Spring Security, but now it does not.

The issue seems to be that if maven is deploying the application to embedded tomcat, then TestNG is starting the applicationContext-test.xml which in turn was importing classpath:/WEB-INF/applicationContext*.xml which is the same import as my web.xml is importing:



The strange thing is, only my Spring Security has the issue. All my other beans start just fine. So as soon as I removed that declaration from my applicationContext-test.xml for TestNG Testing, the error was fixed.

Mick Knutson

Java, JavaEE, J2EE, WebLogic, WebSphere, JBoss, Tomcat, Oracle, Spring, Maven, Architecture, Design, Mentoring, Instructor and Agile Consulting.

View all posts

Java / JavaEE / Spring Boot Channel

BLiNC Supporters

BLiNC Adsense