I have this test
@RunWith(SpringRunner.class)
@ContextConfiguration(locations = "classpath:some-context-test.xml")
@DirtiesContext
public class SomeClassIT {
...
@Test
public void someTestMethod() {
...
}
...
}
which runs with no problems when triggered from IntelliJ IDEA, but fails with the error
[ERROR] someTestMethod(x.y.z.SomeClassIT) Time elapsed: 0.001 s <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'entityManagerFactory' defined in class path resource [META-INF/db.xml]: Invocation of init method
failed; nested exception is org.hibernate.AssertionFailure: AttributeConverter class [class x.y.z.SomeConverter]
registered multiple times
Caused by: org.hibernate.AssertionFailure: AttributeConverter class [class x.y.z.SomeConverter] registered
multiple times
when executed via maven
mvn verify -DskipITs=false
But if I remove maven-shade-plugin config from pom.xml (the project is using it), then test executes with success even via maven.
Found the solution in this Q&A: https://stackoverflow.com/a/56589859/2806801 . The parameter classpathDependencyScopeExclude
of maven-failsafe-plugin:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>[...]</version>
<configuration>
<classpathDependencyScopeExclude>runtime</classpathDependencyScopeExclude>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
DETAILS
Because of maven-shade-plugin the META-INF/db.xml
(imported by some-context-test.xml
) was loaded twice:
After I set parameter classpathDependencyScopeExclude
to runtime
the META-INF/db.xml
was loaded only from
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.