Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.08 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"
  4. xmlns:aop="http://www.springframework.org/schema/aop"
  5. xmlns:context="http://www.springframework.org/schema/context"
  6. xmlns:jee="http://www.springframework.org/schema/jee"
  7. xmlns:lang="http://www.springframework.org/schema/lang"
  8. xmlns:p="http://www.springframework.org/schema/p"
  9. xmlns:tx="http://www.springframework.org/schema/tx"
  10. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  11. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
  12. ">
  13.  
  14. <bean id="transactionManager"
  15. class="org.springframework.orm.hibernate5.HibernateTransactionManager">
  16. <property name="sessionFactory" ref="sessionFactory"/>
  17. </bean>
  18.  
  19. <bean id="sessionFactory"
  20. class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
  21. <property name="dataSource" ref="dataSource" />
  22. <property name="configLocation">
  23. <value>classpath:hibernate.cfg.xml</value>
  24. </property>
  25. <property name="hibernateProperties">
  26. <props>
  27. <prop key="hibernate.show_sql">true</prop>
  28. <prop key="hibernate.dialect">${jdbc.dialect}</prop>
  29. <prop key="hibernate.connection.charSet">UTF-8</prop>
  30. </props>
  31. </property>
  32. </bean>
  33.  
  34. <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
  35. p:driverClassName="${jdbc.driverClassName}"
  36. p:url="${jdbc.databaseUrl}"
  37. p:username="${jdbc.username}"
  38. p:password="${jdbc.password}"/>
  39.  
  40. <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
  41. p:location="/WEB-INF/jdbc.properties"/>
  42.  
  43. <bean id="messageSource"
  44. class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
  45. <property name="basename" value="messages"/>
  46. <property name="defaultEncoding" value="UTF-8"/>
  47. </bean>
  48.  
  49. <tx:annotation-driven transaction-manager="transactionManager"/>
  50. </beans>
  51.  
  52. <?xml version="1.0" encoding="UTF-8"?>
  53. <beans xmlns="http://www.springframework.org/schema/beans"
  54. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  55. xmlns:aop="http://www.springframework.org/schema/aop"
  56. xmlns:context="http://www.springframework.org/schema/context"
  57. xmlns:jee="http://www.springframework.org/schema/jee"
  58. xmlns:lang="http://www.springframework.org/schema/lang"
  59. xmlns:p="http://www.springframework.org/schema/p"
  60. xmlns:tx="http://www.springframework.org/schema/tx"
  61. xmlns:util="http://www.springframework.org/schema/util"
  62. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  63. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
  64. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
  65. http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
  66. http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
  67. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
  68. http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
  69. >
  70.  
  71. <context:annotation-config/>
  72. <context:component-scan base-package="com"/>
  73.  
  74. <import resource="data.xml"/>
  75.  
  76. </beans>
  77.  
  78. <?xml version="1.0" encoding="UTF-8" ?>
  79. <web-app
  80. xmlns="http://java.sun.com/xml/ns/javaee"
  81. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  82. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  83.  
  84. <context-param>
  85. <param-name>contextConfigLocation</param-name>
  86. <param-value>/WEB-INF/root-context.xml</param-value>
  87. </context-param>
  88.  
  89. <listener>
  90. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  91. </listener>
  92.  
  93. <servlet>
  94. <servlet-name>appServlet</servlet-name>
  95. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  96. <init-param>
  97. <param-name>contextConfigLocation</param-name>
  98. <param-value>/WEB-INF/servlet-context.xml</param-value>
  99. </init-param>
  100. <load-on-startup>1</load-on-startup>
  101. </servlet>
  102. <servlet-mapping>
  103. <servlet-name>appServlet</servlet-name>
  104. <url-pattern>/</url-pattern>
  105. </servlet-mapping>
  106.  
  107. <!-- Encoder -->
  108. <filter>
  109. <filter-name>charsetFilter</filter-name>
  110. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  111. <init-param>
  112. <param-name>encoding</param-name>
  113. <param-value>UTF-8</param-value>
  114. </init-param>
  115. <init-param>
  116. <param-name>forceEncoding</param-name>
  117. <param-value>true</param-value>
  118. </init-param>
  119. </filter>
  120. <filter-mapping>
  121. <filter-name>charsetFilter</filter-name>
  122. <url-pattern>/*</url-pattern>
  123. </filter-mapping>
  124. </web-app>
  125.  
  126. jdbc.driverClassName= org.postgresql.Driver
  127. jdbc.dialect=org.hibernate.dialect.PostgreSQLDialect
  128. jdbc.databaseurl=jdbc:postgresql://localhost:5432/shopbase
  129. jdbc.username=user
  130. jdbc.password=1234
  131.  
  132. <?xml version='1.0' encoding='utf-8'?>
  133. <!DOCTYPE hibernate-configuration PUBLIC
  134. "-//Hibernate/Hibernate Configuration DTD//EN"
  135. "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
  136.  
  137. <hibernate-configuration>
  138. <session-factory>
  139. <mapping class="com.model.Product" />
  140. </session-factory>
  141. </hibernate-configuration>
  142.  
  143. import javax.persistence.*;
  144.  
  145. @Entity
  146. @Table(name = "product")
  147. public class Product {
  148.  
  149. @Id
  150. @Column(name = "id")
  151. @GeneratedValue
  152. private int id;
  153.  
  154. @Column(name = "name")
  155. private String name;
  156.  
  157. @Column(name = "price")
  158. private float price;
  159.  
  160. public int getId() {
  161. return id;
  162. }
  163.  
  164. public void setId(int id) {
  165. this.id = id;
  166. }
  167.  
  168. public String getName() {
  169. return name;
  170. }
  171.  
  172. public void setName(String name) {
  173. this.name = name;
  174. }
  175.  
  176. public float getPrice() {
  177. return price;
  178. }
  179.  
  180. public void setPrice(float price) {
  181. this.price = price;
  182. }
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement