我想在我的Spring数据库事务中使用ASPECTJ加载时间编织(在JBOSS上运行)。我已经浪费了整整一天但却无法正常工作。
我已粘贴了我的Java代码以及下面的服务器输出。它应该在数据库中插入1条记录,然后回滚,因为我已经应用了RuntimeException
@Transactional
。但是当它运行时,它总是插入记录并提交事务,它实际上从未实际回滚过它。
WEB-INF / JBoss的-scanning.xml :
<scanning xmlns="urn:jboss:scanning:1.0"/> <!-- this didn't help -->
aop.xml文件:
<aspectj>
<weaver options="-verbose -showWeaveInfo"/>
</aspectj>
Java代码:
package com.test;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.AdviceMode;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableLoadTimeWeaving;
import org.springframework.context.annotation.EnableLoadTimeWeaving.AspectJWeaving;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
public class WebAppInit implements WebApplicationInitializer
{
public void onStartup(ServletContext container) throws ServletException
{
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(AppConfig.class);
context.refresh();
try
{
TestDao dao = context.getBean(TestDao.class);
dao.test();
}
catch (Exception ex)
{
System.out.println(ex.getMessage());
}
}
@Configuration
@EnableLoadTimeWeaving(aspectjWeaving = AspectJWeaving.ENABLED)
@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)
@ComponentScan(basePackages = "com.test")
public static class AppConfig
{
@Bean("vcomDataSource")
public DataSource vcomDataSource()
{
return new JndiDataSourceLookup().getDataSource("java:jboss/com.company.jndi.db");
}
@Bean("vcomTxManager")
DataSourceTransactionManager vcomTxManager(@Qualifier("vcomDataSource") DataSource datasource)
{
return new DataSourceTransactionManager(datasource);
}
}
@Repository
@Transactional
public static class TestDao
{
@Autowired
private DataSource datasource;
@Transactional
public void test()
{
String sql = "insert into nest_rhr_customer (rhr_customer_id) values (nest_rhr_customer_id_seq.nextval)";
JdbcTemplate jdbc = new JdbcTemplate(datasource);
jdbc.update(sql);
throw new RuntimeException("TEST ERROR"); //this should roll back the transaction, but it's not working!!!
}
}
}
服务器输出:
22:43:38,911 INFO [org.jboss.modules] (main) JBoss Modules version 1.3.0.Final-redhat-2
22:43:39,079 INFO [org.jboss.msc] (main) JBoss MSC version 1.0.4.GA-redhat-1
22:43:39,137 INFO [org.jboss.as] (MSC service thread 1-6) JBAS015899: JBoss EAP 6.2.0.GA (AS 7.3.0.Final-redhat-14) starting
22:43:43,120 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found SpringDemo.war in deployment directory. To trigger deployment create a file called SpringDemo.war.dodeploy
22:43:43,120 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found vectrenassets.war in deployment directory. To trigger deployment create a file called vectrenassets.war.dodeploy
22:43:43,139 INFO [org.xnio] (MSC service thread 1-6) XNIO Version 3.0.7.GA-redhat-1
22:43:43,140 INFO [org.jboss.as.server] (Controller Boot Thread) JBAS015888: Creating http management service using socket-binding (management-http)
22:43:43,143 INFO [org.xnio.nio] (MSC service thread 1-6) XNIO NIO Implementation Version 3.0.7.GA-redhat-1
22:43:43,149 INFO [org.jboss.remoting] (MSC service thread 1-6) JBoss Remoting version 3.2.18.GA-redhat-1
22:43:43,174 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 36) JBAS010280: Activating Infinispan subsystem.
22:43:43,186 INFO [org.jboss.as.jacorb] (ServerService Thread Pool -- 37) JBAS016300: Activating JacORB Subsystem
22:43:43,187 INFO [org.jboss.as.security] (ServerService Thread Pool -- 54) JBAS013171: Activating Security Subsystem
22:43:43,191 INFO [org.jboss.as.security] (MSC service thread 1-7) JBAS013170: Current PicketBox version=4.0.19.SP2-redhat-1
22:43:43,193 INFO [org.jboss.as.webservices] (ServerService Thread Pool -- 58) JBAS015537: Activating WebServices Extension
22:43:43,195 INFO [org.jboss.as.clustering.jgroups] (ServerService Thread Pool -- 41) JBAS010260: Activating JGroups subsystem.
22:43:43,198 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 49) JBAS011800: Activating Naming Subsystem
22:43:43,235 INFO [org.jboss.as.jsf] (ServerService Thread Pool -- 44) JBAS012605: Activated the following JSF Implementations: [main, 1.2]
22:43:43,264 INFO [org.jboss.as.connector.logging] (MSC service thread 1-4) JBAS010408: Starting JCA Subsystem (IronJacamar 1.0.23.Final-redhat-1)
22:43:43,267 INFO [org.jboss.as.naming] (MSC service thread 1-5) JBAS011802: Starting Naming Service
22:43:43,272 INFO [org.jboss.as.mail.extension] (MSC service thread 1-3) JBAS015400: Bound mail session [java:jboss/mail/Default]
22:43:43,305 INFO [org.jboss.jaxr] (MSC service thread 1-5) JBAS014000: Started JAXR subsystem, binding JAXR connection factory into JNDI as: java:jboss/jaxr/ConnectionFactory
22:43:43,516 INFO [org.apache.coyote.http11] (MSC service thread 1-5) JBWEB003001: Coyote HTTP/1.1 initializing on : http-/0.0.0.0:8080
22:43:43,518 INFO [org.apache.coyote.http11] (MSC service thread 1-5) JBWEB003000: Coyote HTTP/1.1 starting on: http-/0.0.0.0:8080
22:43:43,518 INFO [org.apache.coyote.ajp] (MSC service thread 1-1) JBWEB003046: Starting Coyote AJP/1.3 on ajp-/0.0.0.0:8009
22:43:43,572 INFO [org.hornetq.core.server] (ServerService Thread Pool -- 60) HQ221000: live server is starting with configuration HornetQ Configuration (clustered=true,backup=false,sharedStore=true,journalDirectory=C:\jboss\devstudio\runtimes\jboss-eap\standalone\data\messagingjournal,bindingsDirectory=C:\jboss\devstudio\runtimes\jboss-eap\standalone\data\messagingbindings,largeMessagesDirectory=C:\jboss\devstudio\runtimes\jboss-eap\standalone\data\messaginglargemessages,pagingDirectory=C:\jboss\devstudio\runtimes\jboss-eap\standalone\data\messagingpaging)
22:43:43,573 INFO [org.hornetq.core.server] (ServerService Thread Pool -- 60) HQ221006: Waiting to obtain live lock
22:43:43,576 INFO [org.jboss.modcluster] (ServerService Thread Pool -- 61) MODCLUSTER000001: Initializing mod_cluster ${project.version}
22:43:43,604 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 32) JBAS010403: Deploying JDBC-compliant driver class oracle.jdbc.OracleDriver (version 12.1)
22:43:43,627 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 32) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
22:43:43,635 WARN [jacorb.codeset] (MSC service thread 1-2) Warning - unknown codeset (Cp1252) - defaulting to ISO-8859-1
22:43:43,651 INFO [org.jboss.modcluster] (ServerService Thread Pool -- 61) MODCLUSTER000032: Listening to proxy advertisements on /224.0.1.105:23364
22:43:43,662 INFO [org.hornetq.core.server] (ServerService Thread Pool -- 60) HQ221013: Using NIO Journal
22:43:43,670 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-7) JBAS010400: Bound data source [java:jboss/com.vectren.povect.jndi.db]
22:43:43,671 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-3) JBAS010400: Bound data source [java:jboss/com.vectren.jndi.db]
22:43:43,671 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-7) JBAS010400: Bound data source [java:jboss/com.vectren.cevvprod.jndi.db]
22:43:43,671 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) JBAS010400: Bound data source [java:jboss/com.vectren.cdayprod.jndi.db]
22:43:43,671 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-3) JBAS010400: Bound data source [java:jboss/com.vectren.cindprod.jndi.db]
22:43:43,671 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-6) JBAS010400: Bound data source [java:jboss/com.vectren.porptvect.jndi.db]
22:43:43,701 INFO [org.jboss.as.jacorb] (MSC service thread 1-2) JBAS016330: CORBA ORB Service started
22:43:43,704 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 36) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
22:43:43,710 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 36) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
22:43:43,810 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-6) JBAS015012: Started FileSystemDeploymentService for directory C:\jboss\devstudio\runtimes\jboss-eap\standalone\deployments
22:43:43,815 INFO [org.hornetq.core.server] (ServerService Thread Pool -- 60) HQ221034: Waiting to obtain live lock
22:43:43,815 INFO [org.hornetq.core.server] (ServerService Thread Pool -- 60) HQ221035: Live Server Obtained live lock
22:43:43,817 INFO [org.jboss.as.server.deployment] (MSC service thread 1-5) JBAS015876: Starting deployment of "vectrenassets.war" (runtime-name: "vectrenassets.war")
22:43:43,817 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015876: Starting deployment of "SpringDemo.war" (runtime-name: "SpringDemo.war")
22:43:43,823 INFO [org.jboss.ws.common.management] (MSC service thread 1-4) JBWS022052: Starting JBoss Web Services - Stack CXF Server 4.2.3.Final-redhat-1
22:43:43,824 INFO [org.jboss.as.remoting] (MSC service thread 1-7) JBAS017100: Listening on 0.0.0.0:4447
22:43:43,824 INFO [org.jboss.as.remoting] (MSC service thread 1-2) JBAS017100: Listening on 127.0.0.1:9999
22:43:43,843 INFO [org.jboss.as.jacorb] (MSC service thread 1-8) JBAS016328: CORBA Naming Service started
22:43:44,274 INFO [org.hornetq.core.server] (ServerService Thread Pool -- 60) HQ221020: Started Netty Acceptor version 3.6.6.Final-redhat-1-fd3c6b7 0.0.0.0:5455 for CORE protocol
22:43:44,281 INFO [org.hornetq.core.server] (ServerService Thread Pool -- 60) HQ221020: Started Netty Acceptor version 3.6.6.Final-redhat-1-fd3c6b7 0.0.0.0:5445 for CORE protocol
22:43:44,357 INFO [org.hornetq.core.server] (ServerService Thread Pool -- 60) HQ221007: Server is now live
22:43:44,357 INFO [org.hornetq.core.server] (ServerService Thread Pool -- 60) HQ221001: HornetQ Server version 2.3.12.Final (2.3.12, 123) [ef946424-3f84-11e4-a825-5140114d1444]
22:43:44,378 INFO [org.hornetq.jms.server] (ServerService Thread Pool -- 61) HQ121005: Invalid "host" value "0.0.0.0" detected for "netty" connector. Switching to "DC4PH6Y1". If this new address is incorrect please manually configure the connector to use the proper one.
22:43:44,403 INFO [org.jboss.as.messaging] (ServerService Thread Pool -- 61) JBAS011601: Bound messaging object to jndi name java:jboss/exported/jms/RemoteConnectionFactory
22:43:44,404 INFO [org.jboss.as.messaging] (ServerService Thread Pool -- 60) JBAS011601: Bound messaging object to jndi name java:/ConnectionFactory
22:43:44,500 INFO [org.jboss.as.connector.deployment] (MSC service thread 1-2) JBAS010406: Registered connection factory java:/JmsXA
22:43:44,591 INFO [org.hornetq.ra] (MSC service thread 1-2) HornetQ resource adaptor started
22:43:44,594 INFO [org.jboss.as.connector.services.resourceadapters.ResourceAdapterActivatorService$ResourceAdapterActivator] (MSC service thread 1-2) IJ020002: Deployed: file://RaActivatorhornetq-ra
22:43:44,596 INFO [org.jboss.as.connector.deployment] (MSC service thread 1-2) JBAS010401: Bound JCA ConnectionFactory [java:/JmsXA]
22:43:45,527 WARN [org.jboss.as.ee] (MSC service thread 1-5) JBAS011006: Not installing optional component org.springframework.web.context.request.async.StandardServletAsyncWebRequest due to an exception (enable DEBUG log level to see the cause)
22:43:45,528 WARN [org.jboss.as.ee] (MSC service thread 1-5) JBAS011006: Not installing optional component org.springframework.http.server.ServletServerHttpAsyncRequestControl due to an exception (enable DEBUG log level to see the cause)
22:43:45,583 INFO [org.jboss.web] (ServerService Thread Pool -- 60) JBAS018210: Register web context: /SpringDemo
22:43:45,604 INFO [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/SpringDemo]] (ServerService Thread Pool -- 60) 1 Spring WebApplicationInitializers detected on classpath
22:43:45,623 INFO [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (ServerService Thread Pool -- 60) Refreshing Root WebApplicationContext: startup date [Wed Aug 23 22:43:45 CDT 2017]; root of context hierarchy
22:43:45,667 INFO [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (ServerService Thread Pool -- 60) Registering annotated classes: [class com.test.WebAppInit$AppConfig]
22:43:45,862 INFO [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (ServerService Thread Pool -- 60) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
22:43:45,936 INFO [org.springframework.context.weaving.DefaultContextLoadTimeWeaver] (ServerService Thread Pool -- 60) Determined server-specific load-time weaver: org.springframework.instrument.classloading.jboss.JBossLoadTimeWeaver
22:43:45,952 INFO [org.springframework.context.weaving.DefaultContextLoadTimeWeaver] (ServerService Thread Pool -- 60) Determined server-specific load-time weaver: org.springframework.instrument.classloading.jboss.JBossLoadTimeWeaver
22:43:45,998 ERROR [stderr] (ServerService Thread Pool -- 60) [ModuleClassLoader@47d6ea60] info AspectJ Weaver Version 1.8.10 built on Monday Dec 12, 2016 at 19:07:48 GMT
22:43:45,999 ERROR [stderr] (ServerService Thread Pool -- 60) [ModuleClassLoader@47d6ea60] info register classloader org.jboss.modules.ModuleClassLoader@47d6ea60
22:43:45,999 ERROR [stderr] (ServerService Thread Pool -- 60) [ModuleClassLoader@47d6ea60] info using configuration /C:/jboss/devstudio/runtimes/jboss-eap/standalone/deployments/SpringDemo.war/META-INF/aop.xml
22:43:45,999 ERROR [stderr] (ServerService Thread Pool -- 60) [ModuleClassLoader@47d6ea60] info using configuration /C:/jboss/devstudio/runtimes/jboss-eap/standalone/deployments/SpringDemo.war/WEB-INF/lib/spring-aspects-4.3.10.RELEASE.jar/META-INF/aop.xml
22:43:46,001 ERROR [stderr] (ServerService Thread Pool -- 60) [ModuleClassLoader@47d6ea60] info register aspect org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect
22:43:46,110 ERROR [stderr] (ServerService Thread Pool -- 60) [ModuleClassLoader@47d6ea60] info register aspect org.springframework.scheduling.aspectj.AnnotationAsyncExecutionAspect
22:43:46,119 ERROR [stderr] (ServerService Thread Pool -- 60) [ModuleClassLoader@47d6ea60] info register aspect org.springframework.transaction.aspectj.AnnotationTransactionAspect
22:43:46,124 ERROR [stderr] (ServerService Thread Pool -- 60) [ModuleClassLoader@47d6ea60] info register aspect org.springframework.transaction.aspectj.JtaAnnotationTransactionAspect
22:43:46,172 ERROR [stderr] (ServerService Thread Pool -- 60) [ModuleClassLoader@47d6ea60] info deactivating aspect 'org.springframework.transaction.aspectj.JtaAnnotationTransactionAspect' as it requires type 'javax.transaction.Transactional' which cannot be found on the classpath
22:43:46,189 ERROR [stderr] (ServerService Thread Pool -- 60) [ModuleClassLoader@47d6ea60] info register aspect org.springframework.cache.aspectj.AnnotationCacheAspect
22:43:46,207 ERROR [stderr] (ServerService Thread Pool -- 60) [ModuleClassLoader@47d6ea60] info register aspect org.springframework.cache.aspectj.JCacheCacheAspect
22:43:46,209 ERROR [stderr] (ServerService Thread Pool -- 60) [ModuleClassLoader@47d6ea60] info deactivating aspect 'org.springframework.cache.aspectj.JCacheCacheAspect' as it requires type 'org.springframework.cache.jcache.interceptor.JCacheAspectSupport' which cannot be found on the classpath
22:43:46,209 ERROR [stderr] (ServerService Thread Pool -- 60) [ModuleClassLoader@47d6ea60] info deactivating aspect 'org.springframework.cache.aspectj.JCacheCacheAspect' as it requires type 'javax.cache.annotation.CacheResult' which cannot be found on the classpath
22:43:47,879 INFO [stdout] (ServerService Thread Pool -- 60) TEST ERROR
22:43:49,676 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 61) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
22:43:49,676 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 62) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
22:43:49,678 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 61) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
22:43:49,678 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 62) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
22:43:49,679 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (MSC service thread 1-2) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
22:43:49,679 INFO [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (MSC service thread 1-2) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
22:43:49,713 INFO [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (ServerService Thread Pool -- 60) ISPN000078: Starting JGroups Channel
22:43:49,757 INFO [stdout] (ServerService Thread Pool -- 60)
22:43:49,757 INFO [stdout] (ServerService Thread Pool -- 60) -------------------------------------------------------------------
22:43:49,757 INFO [stdout] (ServerService Thread Pool -- 60) GMS: address=dc4ph6y1/web, cluster=web, physical address=0.0.0.0:55200
22:43:49,757 INFO [stdout] (ServerService Thread Pool -- 60) -------------------------------------------------------------------
22:43:51,770 INFO [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (ServerService Thread Pool -- 60) ISPN000094: Received new cluster view: [dc4ph6y1/web|0] [dc4ph6y1/web]
22:43:51,793 INFO [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (ServerService Thread Pool -- 60) ISPN000079: Cache local address is dc4ph6y1/web, physical addresses are [0.0.0.0:55200]
22:43:51,796 INFO [org.infinispan.factories.GlobalComponentRegistry] (ServerService Thread Pool -- 60) ISPN000128: Infinispan version: Infinispan 'Delirium' 5.2.7.Final
22:43:51,802 INFO [org.jboss.as.clustering] (MSC service thread 1-8) JBAS010238: Number of cluster members: 1
22:43:51,820 INFO [org.infinispan.factories.TransactionManagerFactory] (ServerService Thread Pool -- 62) ISPN000161: Using a batchMode transaction manager
22:43:51,820 INFO [org.infinispan.factories.TransactionManagerFactory] (ServerService Thread Pool -- 60) ISPN000161: Using a batchMode transaction manager
22:43:51,920 INFO [org.infinispan.jmx.CacheJmxRegistration] (ServerService Thread Pool -- 62) ISPN000031: MBeans were successfully registered to the platform MBean server.
22:43:51,920 INFO [org.infinispan.jmx.CacheJmxRegistration] (ServerService Thread Pool -- 60) ISPN000031: MBeans were successfully registered to the platform MBean server.
22:43:51,927 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 62) JBAS010281: Started default-host/assets cache from web container
22:43:51,927 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 60) JBAS010281: Started repl cache from web container
22:43:51,932 INFO [org.jboss.web] (ServerService Thread Pool -- 62) JBAS018210: Register web context: /assets
22:43:52,004 INFO [org.jboss.as.server] (ServerService Thread Pool -- 33) JBAS018559: Deployed "vectrenassets.war" (runtime-name : "vectrenassets.war")
22:43:52,004 INFO [org.jboss.as.server] (ServerService Thread Pool -- 33) JBAS018559: Deployed "SpringDemo.war" (runtime-name : "SpringDemo.war")
22:43:52,017 INFO [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management
22:43:52,017 INFO [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
22:43:52,017 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss EAP 6.2.0.GA (AS 7.3.0.Final-redhat-14) started in 13404ms - Started 274 of 414 services (134 services are passive or on-demand)
答案 0 :(得分:0)
将@EnableLoadTimeWeaving添加到您的配置