Advertisement
Guest User

Untitled

a guest
Nov 29th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. public static void main(String[] args) {
  2.  
  3. Patient sac = new Patient();
  4. sac.setPatient_Id("M2314");
  5. sac.setPatient_Age(23);
  6. sac.setPatient_Name("Sac");
  7. sac.setPatient_Address("SGTY NY");
  8.  
  9.  
  10. System.out.println("load context");
  11. ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("file:src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml");
  12.  
  13. PatientService patientService = (PatientService) context.getBean("patientService");
  14. patientService.persistPatient(sac);
  15.  
  16. context.close();
  17. }
  18.  
  19. @Service("patientService")
  20. public class PatientServiceImpl implements PatientService{
  21.  
  22. @Autowired
  23. PatientDAO patientdao;
  24.  
  25. @Override
  26. @Transactional
  27. public void persistPatient(Patient patient) {
  28. patientdao.persistPatient(patient);
  29.  
  30. }
  31.  
  32. @Repository("patientdao")
  33. public class PatientDAOImpl implements PatientDAO{
  34.  
  35. @Autowired
  36. private SessionFactory sessionFactory;
  37.  
  38.  
  39. @Override
  40. @Transactional
  41. public void persistPatient(Patient patient) {
  42. sessionFactory.getCurrentSession().persist(patient);
  43.  
  44. }
  45.  
  46. <?xml version="1.0" encoding="UTF-8"?>
  47. <beans:beans xmlns="http://www.springframework.org/schema/mvc"
  48. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
  49. xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
  50. xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
  51. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  52. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
  53.  
  54. <!-- DispatcherServlet Context: defines this servlet's request-processing
  55. infrastructure -->
  56.  
  57. <!-- Enables the Spring MVC @Controller programming model -->
  58. <annotation-driven />
  59.  
  60.  
  61. <resources mapping="/resources/**" location="/resources/" />
  62.  
  63. <!-- Resolves views selected for rendering by @Controllers to .jsp resources
  64. in the /WEB-INF/views directory -->
  65. <beans:bean
  66. class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  67. <beans:property name="prefix" value="/WEB-INF/views/" />
  68. <beans:property name="suffix" value=".jsp" />
  69. </beans:bean>
  70.  
  71. <context:component-scan base-package="com.tela.pms" />
  72.  
  73. <beans:bean id="patientService" class="com.tela.pms.service.impl.PatientServiceImpl"/>
  74. <beans:bean id="patientdao" class="com.tela.pms.dao.impl.PatientDAOImpl"/>
  75.  
  76. <beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
  77. destroy-method="close">
  78. <beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
  79. <beans:property name="url" value="jdbc:mysql://localhost:3306/test" />
  80. <beans:property name="username" value="root" />
  81. <beans:property name="password" value="root" />
  82. </beans:bean>
  83.  
  84. <beans:bean id="sessionFactory"
  85. class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
  86. <beans:property name="dataSource" ref="dataSource"></beans:property>
  87. <beans:property name="annotatedClasses">
  88. <beans:list>
  89. <beans:value>com.tela.pms.domain.Patient</beans:value>
  90. </beans:list>
  91. </beans:property>
  92. <beans:property name="hibernateProperties">
  93. <beans:props>
  94. <beans:prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</beans:prop>
  95. <beans:prop key="hibernate.show_sql">true</beans:prop>
  96. </beans:props>
  97. </beans:property>
  98. </beans:bean>
  99.  
  100. <beans:bean id="transactionManager"
  101. class="org.springframework.orm.hibernate4.HibernateTransactionManager"
  102. p:sessionFactory-ref="sessionFactory">
  103. </beans:bean>
  104.  
  105.  
  106. </beans:beans>
  107.  
  108. <tx:annotation-driven transaction-manager="transactionManager"/>
  109.  
  110. <?xml version="1.0" encoding="UTF-8"?>
  111. <beans:beans xmlns="http://www.springframework.org/schema/mvc"
  112. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
  113. xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
  114. xmlns:tx="http://www.springframework.org/schema/tx"
  115. xsi:schemaLocation="
  116. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
  117. http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
  118. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  119. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
  120.  
  121. <!-- DispatcherServlet Context: defines this servlet's request-processing
  122. infrastructure -->
  123.  
  124. <!-- Enables the Spring MVC @Controller programming model -->
  125. <annotation-driven />
  126.  
  127. <tx:annotation-driven />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement