Guest User

Untitled

a guest
Apr 11th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
  4. xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  6. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
  7. http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
  8. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
  9. <!-- 1 -->
  10. <jdbc:embedded-database id="dataSource" type="H2">
  11. <jdbc:script location="classpath:schema.sql" />
  12. <jdbc:script location="classpath:test-data.sql" />
  13. </jdbc:embedded-database>
  14. <!-- 2 -->
  15. <bean id="transactionManager"
  16. class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  17. <property name="dataSource" ref="dataSource" />
  18. </bean>
  19.  
  20. <tx:annotation-driven />
  21. <!-- 3 -->
  22. <context:component-scan base-package="com.vit.service" />
  23.  
  24. <!-- 4 Define the SqlSessionFactory -->
  25. <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  26. <property name="dataSource" ref="dataSource" />
  27. <property name="typeAliasesPackage" value="com.vit.domain" />
  28. </bean>
  29.  
  30. <!-- 5 Scan for mappers and let them be autowired -->
  31. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  32. <property name="basePackage" value="com.vit.persistence" />
  33. </bean>
  34.  
  35. </beans>
  36.  
  37. public static void main(String[] args) {
  38. GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
  39. ctx.load("classpath:ApplicationContext.xml");
  40. ctx.refresh();
  41.  
  42. PersonService personService = ctx.getBean("personService", PersonService.class);
  43. ...
  44. }
Add Comment
Please, Sign In to add comment