Advertisement
Guest User

Untitled

a guest
Feb 8th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.19 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  3. <display-name>spring-mvc-crud-demo</display-name>
  4.  
  5. <welcome-file-list>
  6. <welcome-file>index.jsp</welcome-file>
  7. <welcome-file>index.html</welcome-file>
  8. </welcome-file-list>
  9.  
  10. <servlet>
  11. <servlet-name>dispatcher</servlet-name>
  12. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  13. <init-param>
  14. <param-name>contextConfigLocation</param-name>
  15. <param-value>/WEB-INF/spring.xml</param-value>
  16. </init-param>
  17. <load-on-startup>1</load-on-startup>
  18. </servlet>
  19.  
  20. <servlet-mapping>
  21. <servlet-name>dispatcher</servlet-name>
  22. <url-pattern>/spring/*</url-pattern>
  23. </servlet-mapping>
  24. </web-app>
  25.  
  26. <?xml version="1.0" encoding="UTF-8"?>
  27. <beans xmlns="http://www.springframework.org/schema/beans"
  28. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  29. xmlns:context="http://www.springframework.org/schema/context"
  30. xmlns:tx="http://www.springframework.org/schema/tx"
  31. xmlns:mvc="http://www.springframework.org/schema/mvc"
  32. xsi:schemaLocation="
  33. http://www.springframework.org/schema/beans
  34. http://www.springframework.org/schema/beans/spring-beans.xsd
  35. http://www.springframework.org/schema/context
  36. http://www.springframework.org/schema/context/spring-context.xsd
  37. http://www.springframework.org/schema/mvc
  38. http://www.springframework.org/schema/mvc/spring-mvc.xsd
  39. http://www.springframework.org/schema/tx
  40. http://www.springframework.org/schema/tx/spring-tx.xsd">
  41.  
  42. <!-- Add support for component scanning -->
  43. <context:component-scan base-package="com.spring.controller" />
  44.  
  45. <!-- Add support for conversion, formatting and validation support -->
  46. <mvc:annotation-driven/>
  47.  
  48. <!-- Define Spring MVC view resolver -->
  49. <bean
  50. class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  51. <property name="prefix" value="/WEB-INF/view/" />
  52. <property name="suffix" value=".jsp" />
  53. </bean>
  54.  
  55. <!-- Step 1: Define Database DataSource / connection pool -->
  56. <bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
  57. destroy-method="close">
  58. <property name="driverClass" value="com.mysql.jdbc.Driver" />
  59. <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/spring_student?useSSL=false" />
  60. <property name="user" value="root" />
  61. <property name="password" value="1234" />
  62.  
  63. <!-- these are connection pool properties for C3P0 -->
  64. <property name="minPoolSize" value="5" />
  65. <property name="maxPoolSize" value="20" />
  66. <property name="maxIdleTime" value="30000" />
  67. </bean>
  68.  
  69. <!-- Step 2: Setup Hibernate session factory -->
  70. <bean id="sessionFactory"
  71. class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
  72. <property name="dataSource" ref="myDataSource" />
  73. <property name="packagesToScan" value="com.spring.entity" />
  74. <property name="hibernateProperties">
  75. <props>
  76. <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
  77. <prop key="hibernate.show_sql">true</prop>
  78. </props>
  79. </property>
  80. </bean>
  81.  
  82. <!-- Step 3: Setup Hibernate transaction manager -->
  83. <bean id="myTransactionManager"
  84. class="org.springframework.orm.hibernate5.HibernateTransactionManager">
  85. <property name="sessionFactory" ref="sessionFactory"/>
  86. </bean>
  87.  
  88. <!-- Step 4: Enable configuration of transactional behavior based on annotations -->
  89. <tx:annotation-driven transaction-manager="myTransactionManager" />
  90.  
  91. </beans>
  92.  
  93. package spring.controller;
  94.  
  95. import org.springframework.stereotype.Controller;
  96. import org.springframework.web.bind.annotation.RequestMapping;
  97. import org.springframework.web.bind.annotation.ResponseBody;
  98.  
  99. @Controller
  100. public class StudentController {
  101.  
  102. @RequestMapping("/list")
  103. @ResponseBody
  104. public String list(){
  105. return "student/list";
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement