Spring+MirageSQLでログイン処理を実装しようとしているのですが、
SQLを発行しようとすると、
java.lang.IllegalStateException: It seems not to be existing a transaction.
となってしまいます。
java
1@Controller 2public class LoginController { 3 public Player player; 4 5 @Autowired(required=true) 6 protected PlayerService playerService; 7 8 @RequestMapping(value = "/auth", method = RequestMethod.POST) 9 public String auth(Model model,@ModelAttribute("playerForm") PlayerForm playerForm) { 10 player = playerService.findByLoginId(playerForm.getLoginId()); 11 return "index"; 12 } 13}
java
1@Service 2public class PlayerService { 3 4 @Autowired 5 SqlManager sqlManager; 6 7 @SuppressWarnings("deprecation") 8 @Transactional 9 public Player findByLoginId(String loginId) { 10 return sqlManager.getResultListBySql(Player.class, "select * from player where loginId=?", loginId).get(0); 11 } 12 13}
プロキシによるAOPの弱点に記載されている状況と同じだと思うのですが、
具体的にどのように実装すればトランザクション管理の中でデータベースアクセスができるのでしょうか。
お忙しいところ申し訳ありませんがご教授願えませんでしょうか。
追記:
servlet-context.xmlがなかったのですが、中身から判断して
mvc-config.xmlを記載しておきます。
xml
1<?xml version="1.0" encoding="UTF-8"?> 2 3<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" 5 xmlns:tx="http://www.springframework.org/schema/tx" 6 xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd 7 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 8 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 9 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> 10 11 <!-- Uncomment and your base-package here: 12 <context:component-scan 13 base-package="org.springframework.samples.web"/> --> 14 15 16 <mvc:annotation-driven /> 17 <mvc:resources mapping="/css/**" location="/WEB-INF/css/" /> 18 <mvc:resources mapping="/js/**" location="/WEB-INF/js/" /> 19 <context:component-scan base-package="cx.myhome.*********"/> 20 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 21 <!-- Example: a logical view name of 'showMessage' is mapped to '/WEB-INF/jsp/showMessage.jsp' --> 22 <property name="prefix" value="/WEB-INF/view/"/> 23 <property name="suffix" value=".jsp"/> 24 </bean> 25<tx:annotation-driven /> 26</beans> 27
トランザクションマネージャの設定の記述があるのは
application-config.xmlでした。
xml
1<?xml version="1.0" encoding="UTF-8"?> 2 3<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:context="http://www.springframework.org/schema/context" 5 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 6 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> 7 8 <!-- Uncomment and add your base-package here: 9 <context:component-scan 10 base-package="org.springframework.samples.service"/> --> 11<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> 12 <property name="driverClassName" value="com.mysql.jdbc.Driver" /> 13 <property name="url" value="jdbc:mysql://localhost:3306/test" /> 14 <property name="username" value="****" /> 15 <property name="password" value="****" /> 16</bean> 17 18<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 19 <property name="dataSource" ref="dataSource"/> 20</bean> 21 22<bean id="connectionProvider" class="jp.sf.amateras.mirage.integration.spring.SpringConnectionProvider"> 23 <property name="transactionManager" ref="transactionManager" /> 24</bean> 25 26<bean id="dialect" class="jp.sf.amateras.mirage.dialect.MySQLDialect" /> 27 28<bean id="sqlManager" class="jp.sf.amateras.mirage.SqlManagerImpl"> 29 <property name="connectionProvider" ref="connectionProvider" /> 30 <property name="dialect" ref="dialect" /> 31</bean> 32</beans>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/04/18 09:38