2012-11-15 31 views
0

仅当使用我的QA配置文件构建时,才会出现此问题,例如, MVN全新安装-Pqa使用Codehaus&EnversHibernateToolTask​​构建时,Autowired Bean的类型不正确

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"/> 

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

+0

是'BackofficeReportingService'实现任何接口?如果没有,则创建一个并仅通过该接口引用此类。将CGLIB添加到您的CLASSPATH并启用CGLIB代理*应该也会有帮助。 –

+0

这不是,但我会尝试并报告回来。谢谢。 –

回答

0

此信誉归功于Tomasz Nurkiewicz。 为reportingService创建接口修复了此问题。

我不清楚为什么这个问题开始了,为什么在几个月不变的reportingService,或者为什么大多数其他服务都没有接口就可以正常注入,但我非常感谢Tomasz!一个绿色球体而不是一个黄色球体!