无法使用事务管理器 - 自动装配以异常结束

时间:2015-07-13 18:03:55

标签: java spring

我永远不会想到弹簧配置会出现如此巨大的问题,但我无法使用@Transactional注释完成我的项目(我正在使用JPA)。每次我在使用@Transactional注释的实体中获得没有类型的限定bean。我的申请背景:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
        http://www.springframework.org/schema/data/jpa
        http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">



    <!-- we can use annotations -->
    <context:annotation-config />

    <!--&lt;!&ndash; package to look for annotated classes &ndash;&gt;-->
    <context:component-scan base-package="a.b.c.d.service" />


    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <!-- we will manage transactions with annotations -->
    <tx:annotation-driven transaction-manager="transactionManager"/>

    <!--&lt;!&ndash; data source for our database &ndash;&gt;-->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="oracle.jdbc.OracleDriver" />
        <property name="url" value="jdbc:oracle:thin:@//oracle11:1521/deviso" />
        <property name="username" value="aaa" />
        <property name="password" value="xxx" />
    </bean>

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="myPersistenceUnit"/>
        <property name="packagesToScan" value="a.b.c.d.domain" />
        <property name="dataSource" ref="dataSource"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="false"/>
                <property name="generateDdl" value="true"/>
                <property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect"/>
            </bean>
        </property>

    </bean>

    <jpa:repositories base-package="a.b.c.d.repository"
                      entity-manager-factory-ref="entityManagerFactory">
    <!--transaction-manager-ref="transactionManager">-->

    </jpa:repositories>

</beans>

你能告诉我一些我的设置有什么问题吗?

编辑:我的堆栈跟踪:

2015-07-13 19:31:38,230 ERROR [org.jboss.as.webservices.invocation.InvocationHandlerJAXWS] (default task-3) JBAS015594: Method invocation failed with exception: org.springframework.beans.factory.BeanCreationException: Injection of autowired dependencies failed for class [class a.b.c.d.ws.XMLProviderEndpointImpl$$$view1]; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private a.b.c.d.service.XMLProfileService a.b.c.d.ws.XMLProviderEndpointImpl.profileService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [a.b.c.d.service.XMLProfileService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}: java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Injection of autowired dependencies failed for class [class a.b.c.d.ws.XMLProviderEndpointImpl$$$view1]; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private a.b.c.d.service.XMLProfileService a.b.c.d.ws.XMLProviderEndpointImpl.profileService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [a.b.c.d.service.XMLProfileService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.jboss.as.webservices.invocation.AbstractInvocationHandler.getComponentView(AbstractInvocationHandler.java:85)
    at org.jboss.as.webservices.invocation.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:117)
    at org.jboss.wsf.stack.cxf.JBossWSInvoker.performInvocation(JBossWSInvoker.java:175)
    at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:104)
    at org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.invoke(AbstractJAXWSMethodInvoker.java:237)
    at org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:69)
    at org.jboss.wsf.stack.cxf.JBossWSInvoker.invoke(JBossWSInvoker.java:146)
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [rt.jar:1.7.0_71]
    at java.util.concurrent.FutureTask.run(FutureTask.java:262) [rt.jar:1.7.0_71]
    at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:107)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:241)
    at org.jboss.wsf.stack.cxf.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:97)
    at org.jboss.wsf.stack.cxf.transport.ServletHelper.callRequestHandler(ServletHelper.java:131)
    at org.jboss.wsf.stack.cxf.CXFServletExt.invoke(CXFServletExt.java:88)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:286)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:206)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
    at org.jboss.wsf.stack.cxf.CXFServletExt.service(CXFServletExt.java:136)
    at org.jboss.wsf.spi.deployment.WSFServlet.service(WSFServlet.java:140) [jbossws-spi-2.3.1.Final.jar:2.3.1.Final]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:63) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:247) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:76) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:166) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:197) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:759) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_71]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_71]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_71]
Caused by: org.springframework.beans.factory.BeanCreationException: Injection of autowired dependencies failed for class [class a.b.c.d.ws.XMLProviderEndpointImpl$$$view1]; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private a.b.c.d.service.XMLProfileService a.b.c.d.ws.XMLProviderEndpointImpl.profileService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [a.b.c.d.service.XMLProfileService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.processInjection(AutowiredAnnotationBeanPostProcessor.java:319) [spring-beans-4.0.9.RELEASE.jar:4.0.9.RELEASE]
    at org.springframework.web.context.support.SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(SpringBeanAutowiringSupport.java:85) [spring-web-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.web.context.support.SpringBeanAutowiringSupport.<init>(SpringBeanAutowiringSupport.java:68) [spring-web-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at a.b.c.d.ws.XMLProviderEndpointImpl.<init>(XMLProviderEndpointImpl.java:25) [classes:]
    at a.b.c.d.ws.XMLProviderEndpointImpl$$$view1.<init>(Unknown Source) [classes:]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.7.0_71]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [rt.jar:1.7.0_71]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.7.0_71]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526) [rt.jar:1.7.0_71]
    at java.lang.Class.newInstance(Class.java:379) [rt.jar:1.7.0_71]
    at org.jboss.invocation.proxy.AbstractClassFactory.newInstance(AbstractClassFactory.java:225)
    at org.jboss.invocation.proxy.ProxyFactory.newInstance(ProxyFactory.java:270)
    at org.jboss.as.ee.component.ViewService$DefaultViewInstanceFactory.createViewInstance(ViewService.java:271)
    at org.jboss.as.ee.component.ViewService$View.createInstance(ViewService.java:177)
    at org.jboss.as.ee.component.ViewService$View.createInstance(ViewService.java:173)
    at org.jboss.as.webservices.invocation.AbstractInvocationHandler.getComponentView(AbstractInvocationHandler.java:83)
    ... 49 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private a.b.c.d.service.XMLProfileService a.b.c.d.ws.XMLProviderEndpointImpl.profileService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [a.b.c.d.service.XMLProfileService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:522) [spring-beans-4.0.9.RELEASE.jar:4.0.9.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) [spring-beans-4.0.9.RELEASE.jar:4.0.9.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.processInjection(AutowiredAnnotationBeanPostProcessor.java:316) [spring-beans-4.0.9.RELEASE.jar:4.0.9.RELEASE]
    ... 64 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [a.b.c.d.service.XMLProfileService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1118) [spring-beans-4.0.9.RELEASE.jar:4.0.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:967) [spring-beans-4.0.9.RELEASE.jar:4.0.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:862) [spring-beans-4.0.9.RELEASE.jar:4.0.9.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:494) [spring-beans-4.0.9.RELEASE.jar:4.0.9.RELEASE]
    ... 66 more

代码很简单。 DTO没有逻辑,只有原始类型。

@Transactional
public void update(String password, XMLProviderProfileDTO dto) {
}

当我删除Transactional注释时,一切正常,所以我假设有一些东西与代理transstactional类。

0 个答案:

没有答案