我使用Maven使用Spring管理我的Web应用程序。我有两个主要目录 - / src / main / java和/ src / test / java - 其中所有测试内容都是(测试,模拟等)。 测试从maven命令行和我的IDE顺利运行。问题是当我部署我的应用程序时,我收到此消息:
java.lang.IllegalStateException: More than one bean of type [pl.m4ks.comics.dao.IComicDAO] found, you have to specify the name of the bean (@SpringBean(name="foo")) in order to resolve this conflict. Matched beans: comicDAO,comicDAOMock
at org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getBeanNameOfClass(AnnotProxyFieldValueFactory.java:231)
但问题是comicDAOMock位于/ scr / test目录内,在非测试部署期间应该不可见!我用
<context:component-scan base-package="pl.m4ks.comics"/>
<context:annotation-config />
在我的context.xml中(用于测试我使用其他手动连接bean的上下文)。
在pom.xml中我有:
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/java</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
<testResource>
<directory>src/test/resources</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
所以我以为我将它们分开了。如何解决这个问题,我的意思是从我的部署运行中完全排除所有测试内容(我使用'mvn jetty:run'命令运行)