使用Codehaus&amp ;;构建时,自动装配的Bean不是正确的类型EnversHibernateToolTask

时间:2012-11-15 12:25:28

标签: spring hibernate maven dependency-injection

此问题仅在我使用我的QA配置文件构建时出现,例如mvn clean install -Pqa

Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'reportingService' must be of type [com.testProjects.project.backoffice.service.BackofficeReportingService], but was actually of type [$Proxy78]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:360)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:442)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:416)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:549)
    at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:150)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:303)
    ... 54 more
Tests run: 563, Failures: 1, Errors: 0, Skipped: 562, Time elapsed: 19.656 sec <<< FAILURE!

我的POM的相关位:

<profile>
    <id>qa</id>
    <properties>
        <tomcat.url>http://etc:8081/manager/text</tomcat.url>
        <war.name>project-backoffice</war.name>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <version>1.1.1</version>
                <configuration>
                    <deployer>
                        <deployables>
                            <deployable>
                                <properties>
                                    <context>${war.name}</context>
                                </properties>
                            </deployable>
                        </deployables>
                    </deployer>
                    <wait>true</wait>
                    <container>
                        <containerId>tomcat7x</containerId>
                        <type>remote</type>
                    </container>
                    <configuration>
                        <type>runtime</type>
                        <properties>
                            <cargo.tomcat.manager.url>${tomcat.url}</cargo.tomcat.manager.url>
                            <cargo.remote.username>admin</cargo.remote.username>
                            <cargo.remote.password>admin</cargo.remote.password>
                        </properties>
                    </configuration>
                </configuration>
                <executions>
                    <execution>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>redeploy</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

构建部分:

<artifactId>maven-antrun-plugin </artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <phase>install</phase>
            <configuration>
                <tasks>
                    <property name="compile_classpath" refid="maven.compile.classpath" />
                    <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.EnversHibernateToolTask" classpath="${compile_classpath}" />
                    <hibernatetool destdir="${project.build.directory}">
                        <annotationconfiguration configurationfile="${project.build.outputDirectory}/backoffice.hibernate.cfg.xml" propertyfile="${project.build.directory}/test-classes/hibernatetools.properties" />
                        <hbm2ddl create="true" drop="true" export="false" format="true" outputfilename="project-schema.ddl" />
                    </hibernatetool>
                    <hibernatetool destdir="${project.build.directory}">
                        <annotationconfiguration configurationfile="${project.build.outputDirectory}/backoffice.hibernate.docs.cfg.xml" propertyfile="${project.build.directory}/test-classes/hibernatetools.properties" />
                        <hbm2ddl create="true" drop="true" export="false" format="true" outputfilename="document-schema.ddl" />
                    </hibernatetool>
                </tasks>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>

有问题的控制器:

@Controller
@RequestMapping("/reporting/")
public class ReportingController {

    private final static Logger logger = LoggerFactory.getLogger(ReportingController.class);

    @Resource
    private BackofficeReportingService reportingService;

有问题的服务:

@Transactional(propagation=Propagation.NEVER)
@Service
public class BackofficeReportingService {

尝试在上下文中添加一个定义,也尝试设置CGLIB代理,没有效果。

<bean id="reportingService" class="com.project.backoffice.service.BackofficeReportingService"/>

任何帮助都会非常感激,它会使我的构建“不稳定”,我很想知道发生了什么。

1 个答案:

答案 0 :(得分:0)

归功于Tomasz Nurkiewicz。 为reportingService创建一个接口,修复了这个问题。

我不清楚为什么这个问题开始了,以及为什么在reportService中保持不变,或者为什么大多数其他服务在没有接口的情况下都能正常注入,但我非常感谢Tomasz! Huzzah为绿色球体而不是黄色球体!