Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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:jdbc="http://www.springframework.org/schema/jdbc" 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.1.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
- http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
- <!-- 1 -->
- <jdbc:embedded-database id="dataSource" type="H2">
- <jdbc:script location="classpath:schema.sql" />
- <jdbc:script location="classpath:test-data.sql" />
- </jdbc:embedded-database>
- <!-- 2 -->
- <bean id="transactionManager"
- class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource" />
- </bean>
- <tx:annotation-driven />
- <!-- 3 -->
- <context:component-scan base-package="com.vit.service" />
- <!-- 4 Define the SqlSessionFactory -->
- <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
- <property name="dataSource" ref="dataSource" />
- <property name="typeAliasesPackage" value="com.vit.domain" />
- </bean>
- <!-- 5 Scan for mappers and let them be autowired -->
- <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
- <property name="basePackage" value="com.vit.persistence" />
- </bean>
- </beans>
- public static void main(String[] args) {
- GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
- ctx.load("classpath:ApplicationContext.xml");
- ctx.refresh();
- PersonService personService = ctx.getBean("personService", PersonService.class);
- ...
- }
Add Comment
Please, Sign In to add comment