일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- jpa
- SpringBoot
- Open Source
- JavaScript
- 오픈소스
- JDBC
- Tomcat
- spring
- 문서
- error
- Eclipse
- myBatis
- Spring Boot
- MySQL
- Source
- oracle
- AJAX
- STS
- MSSQL
- maven
- Core Java
- PostgreSQL
- 설정
- Exception
- Python
- IntelliJ
- Docker
- ubuntu
- git
- Thymeleaf
- Today
- Total
헤르메스 LIFE
[Spring] Spring + mySql 설정 본문
<bean id="defaultDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name ="driverClassName" value ="${mysql.jdbc.driverClassName}" />
<property name ="url" value ="${mysql.jdbc.url}" />
<property name ="username" value ="${mysql.jdbc.username}" />
<property name ="password" value ="${mysql.jdbc.password}" />
<property name ="initialSize" value ="10"/>
<property name ="maxActive" value ="30"/>
<property name ="maxIdle" value ="15" />
<property name ="minIdle" value ="15" />
<property name ="testOnBorrow" value ="false" />
<property name ="validationQuery" value ="select 1" />
<property name ="timeBetweenEvictionRunsMillis" value ="10000" />
<property name ="testWhileIdle" value ="true" />
<property name ="numTestsPerEvictionRun" value ="3" />
<property name ="minEvictableIdleTimeMillis" value ="-1" />
</bean>
<!-- define the SqlSessionFactory -->
<bean id="defaultSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name ="dataSource" ref="defaultDataSource" />
<property name ="typeAliasesPackage" value ="com.sample" />
<property name ="configLocation" value ="classpath:config/mybatisConfig.xml"/>
<property name ="mapperLocations" value ="classpath*:com/sample/**/sql/*.xml" />
</bean>
<bean id="defaultSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg ref="defaultSqlSessionFactory"/>
</bean>
<!-- transaction manager, use JtaTransactionManager for global tx -->
<bean id="defaultTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name ="dataSource" ref="defaultDataSource" />
</bean>
<tx:annotation-driven transaction-manager="defaultTransactionManager"/>
SampleServiceResourceImpl.java
@RequestMapping("/category")
@Controller
public class SampleServiceResourceImpl extends BaseServiceResource implements SampleServiceResource {
@Autowired
private SampleBiz sampleBiz;
@RequestMapping(value = "/samples/tx01", method = RequestMethod.POST)
public ModelAndView txSample01(@RequestBody SampleVO sampleVO) throws Exception {
log.debug("tx sample value : " + sampleVO.toString());
int result = sampleBiz.txSample01(sampleVO);
return success("list", sampleBiz.getSampleList());
}
}SampleDAOImpl.java
@Service("sampleBiz")
public class SampleBizImpl extends BaseBIZ implements SampleBiz{
@Autowired
private SampleDAO sampleDAO;
@Override
@Transactional(readOnly = false)
public int txSample01(SampleVO sampleVO) throws Exception {
return
sampleDAO.insertSample(sampleVO);
}
}
@Repository("sampleDAO")
public class SampleDAOImpl extends BaseDAO implements SampleDAO {
@Override
public int insertSample(SampleVO sampleVO) throws Exception {
return getSqlSession().insert("com.sample.guide.dao.SampleDAO.insertSample", sampleVO);
}
}
'Spring Framework' 카테고리의 다른 글
[Spring] 스프링MVC – 개괄 (0) | 2012.03.12 |
---|---|
[DataSource] org.apache.commons.dbcp.BasicDataSource Connection Pool 설정 (0) | 2012.02.23 |
[DBCP]DBCP (Database connection pooling services) (0) | 2012.02.15 |
[Spring] DB Connection (0) | 2012.02.15 |
[Spring] Annotation Reference for Spring Projects (0) | 2012.01.19 |