0

仅当我使用我的 QA Profile 构建时才会出现此问题,例如 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"/>

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

4

1 回答 1

0

这要归功于 Tomasz Nurkiewicz。为 reportingService 创建一个接口解决了这个问题。

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

于 2012-11-16T15:55:04.153 回答