Guest User

Untitled

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