実行が到達したときに、トランザクションに問題があります
taskExecutor.execute();
例外が発生します:
原因: org.springframework.transaction.IllegalTransactionStateException: 伝搬「必須」でマークされたトランザクションの既存のトランザクションが見つかりません
このエラーは一目瞭然ですが、正しく動作させることができません。
これは、コントローラーを取得して呼び出しを行う方法です。
ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/applicationContext.xml");
BeanFactory beanFactory = context;
FacadeControler f = beanFactory.getBean("facadeController");
f.method(reservation);
これは私のFacadeController
です:
package xxx;
import ...
@Service
public class FacadeControllerImpl implements FacadeController {
static Logger logger = Logger.getLogger(FacadeControllerImpl.class);
@Qualifier("executor")
@Autowired
private TaskExecutor taskExecutor;
@Transactional(propagation=Propagation.REQUIRED)
public Reservation method(Reservation reservationFromEndpoint){
...
taskExecutor.execute();
...
}
は次のExecutor
とおりです。
@Component("executor")
public class QueueTaskExecutor implements TaskExecutor {
final static Logger logger = LoggerFactory.getLogger(QueueTaskExecutor.class);
@Autowired
protected QueuedTaskHolderDao queuedTaskDao;
@Autowired
protected Serializer serializer;
@Override
@Transactional(propagation=Propagation.MANDATORY)
public void execute(Runnable task) {
logger.debug("Trying to enqueue: {}", task);
AbstractBaseTask abt;
try {
abt = AbstractBaseTask.class.cast(task);
} catch (ClassCastException e) {
logger.error("Only runnables that extends AbstractBaseTask are accepted.");
throw new IllegalArgumentException("Invalid task: " + task);
}
// Serialize the task
QueuedTaskHolder newTask = new QueuedTaskHolder();
byte[] serializedTask = this.serializer.serializeObject(abt);
newTask.setTriggerStamp(abt.getTriggerStamp());
logger.debug("New serialized task takes {} bytes", serializedTask.length);
newTask.setSerializedTask(serializedTask);
// Store it in the db
this.queuedTaskDao.persist(newTask);
// POST: Task has been enqueued
}
}
これが私のものapplicationContext.xml
です:
<?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:task="http://www.springframework.org/schema/task"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!-- Where to look for Spring components -->
<context:annotation-config />
<context:component-scan base-package="com.xxx"/>
<!-- @Configurable with AspectJ -->
<context:spring-configured/>
<!-- A task scheduler that will call @Scheduled methods -->
<!-- <task:scheduler id="myScheduler" pool-size="10"/> -->
<!-- <task:annotation-driven scheduler="myScheduler"/> -->
<!-- DataSource -->
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="myDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/bbdd"/>
<property name="username" value="user"/>
<property name="password" value="pass"/>
</bean>
<!-- JPA Entity Manager -->
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="myEntityManagerFactory">
<property name="dataSource" ref="myDataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"></bean>
</property>
<property name="persistenceUnitName" value="comm_layer" />
<property name="jpaPropertyMap">
<map>
<entry key="eclipselink.weaving" value="false"/>
<entry key="eclipselink.ddl-generation" value="create-or-extend-tables"/>
<entry key="eclipselink.logging.level" value="INFO"/>
</map>
</property>
</bean>
<!-- Transaction management -->
<tx:annotation-driven mode="aspectj" />
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />
</property>
<property name="entityManagerFactory" ref="myEntityManagerFactory"/>
</bean>
<bean id="facadeController" class="xxx.FacadeControllerImpl">