下面是我的applicationContext.xml。 tx是xmlns的一部分,并指定了schemalocation。我没有得到构建错误,但在下面获得运行时异常。
这是我尝试添加
的时候 <tx:annotation-driven transaction-manager="txManager" />`enter code here`
使用spring:tx依赖的pom.xml的Pesudo也在下面。
////...
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<springframework.version>4.2.4.RELEASE</springframework.version>
<jacksonframework.version>2.7.5</jacksonframework.version>
</properties>
...///
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${springframework.version}</version>
</dependency>
...////
申请背景:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
<!-- Persistence layer -->
<context:annotation-config />
<context:component-scan base-package="com.tax.data" />
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="oracleds" />
</bean>
<tx:annotation-driven transaction-manager="txManager" />
<!-- <jee:jndi-lookup id="oracleds" jndi-name="java:jboss/datasources/projectDS"/> -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="oracleds" />
<property name="configLocation" value="classpath:config/myBatis-config.xml" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.tax.data.persistence.mapper" />
</bean>
</beans>
例外是:
14:20:48,393 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (ServerService Thread Pool -- 80) Loading XML bean definitions from class path resource [config/applicationContext.xml]
147 14:20:51,392 WARN [org.jboss.modules] (ServerService Thread Pool -- 80) Failed to define class org.springframework.transaction.event.TransactionalEventListenerFactory in Module "deployment.mex.ear.mex.war:main" from Service Module Loader: java.lang.NoClassDefFoundError: Failed to link org/springframework/transaction/event/TransactionalEventListenerFactory (Module "deployment.DataServiceLoad.ear.DataServiceLoad.war:main" from Service Module Loader): org/springframework/context/event/EventListenerFactory
148 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
149 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
150 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
151 at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
152 at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:446)
153 at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:274)
154 at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:78)
155 at org.jboss.modules.Module.loadModuleClass(Module.java:606)
156 at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
157 at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)
158 at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)
159 at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)
160 at org.springframework.transaction.config.AnnotationDrivenBeanDefinitionParser.registerTransactionalEventListenerFactory(AnnotationDrivenBeanDefinitionParser.java:92)
161 at org.springframework.transaction.config.AnnotationDrivenBeanDefinitionParser.parse(AnnotationDrivenBeanDefinitionParser.java:60)
162 at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:74)
163 at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1411)
164 at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1401)
165 at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:168)
166 at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:138)
167 at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:94)
168 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508)
169 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392)
170 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
171 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
172 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
173 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
174 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
175 at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
176 at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
177 at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
178 at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:542)
179 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)
180 at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
181 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
182 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
183 at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:187)
184 at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:200)
185 at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:171)
186 at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
187 at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
188 at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
189 at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
190 at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
191 at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
192 at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
193 at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:234)
194 at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100)
195 at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:82)
196 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
197 at java.util.concurrent.FutureTask.run(FutureTask.java:266)
198 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
199 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
200 at java.lang.Thread.run(Thread.java:748)
201 at org.jboss.threads.JBossThread.run(JBossThread.java:320)
202 14:20:51,394 ERROR [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 80) Context initialization failed: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [config/applicationContext.xml]; nested exception is java.lang.NoClassDefFoundError: Failed to link org/springframework/transaction/event/TransactionalEventListenerFactory (Module "deployment.mex.ear.mex.war:main" from Service Module Loader): org/springframework/context/event/EventListenerFactory
203 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:414)
204 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
205 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
206 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
207 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
208 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
209 at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
210 at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
211 at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
212 at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:542)
213 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)
214 at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
215 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
216 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
217 at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:187)
218 at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:200)
219 at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:171)
220 at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
221 at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
222 at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
223 at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
224 at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
225 at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
226 at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
227 at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:234)
228 at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100)
229 at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:82)
230 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
231 at java.util.concurrent.FutureTask.run(FutureTask.java:266)
232 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
233 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
234 at java.lang.Thread.run(Thread.java:748)
235 at org.jboss.threads.JBossThread.run(JBossThread.java:320)
236 Caused by: java.lang.NoClassDefFoundError: Failed to link org/springframework/transaction/event/TransactionalEventListenerFactory (Module "deployment.mex.ear.mex.war:main" from Service Module Loader): org/springframework/context/event/EventListenerFactory
答案 0 :(得分:1)
异常消息令人困惑,但它说无法加载TransactionalEventListenerFactory
,因为找不到EventListenerFactory
。 EventListenerFactory
来自spring-context,仅在版本4.2之后根据javadoc提供。升级你的spring-context版本可以解决这个问题。
此外,spring-tx仅具有对spring-context的可选依赖性,因此spring-context不会显示为传递依赖项,并且默认情况下工具不会向您显示依赖项版本不匹配(http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html)。