Advertisement
oke_google

Spring Hibernate CRUD xml

Feb 3rd, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 2.88 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:context="http://www.springframework.org/schema/context"
  5.    xmlns:tx="http://www.springframework.org/schema/tx"
  6.     xmlns:mvc="http://www.springframework.org/schema/mvc"
  7.     xsi:schemaLocation="
  8.         http://www.springframework.org/schema/beans
  9.         http://www.springframework.org/schema/beans/spring-beans.xsd
  10.         http://www.springframework.org/schema/context
  11.         http://www.springframework.org/schema/context/spring-context.xsd
  12.         http://www.springframework.org/schema/mvc
  13.         http://www.springframework.org/schema/mvc/spring-mvc.xsd
  14.         http://www.springframework.org/schema/tx
  15.         http://www.springframework.org/schema/tx/spring-tx.xsd">
  16.  
  17.     <!-- Add support for component scanning -->
  18.     <context:component-scan base-package="com.rsia.madura" />
  19.  
  20.     <!-- Add support for conversion, formatting and validation support -->
  21.     <mvc:resources mapping="/resources/**" location="/resources/"/>
  22.     <mvc:annotation-driven/>
  23.    
  24.  
  25.     <!-- Define Spring MVC view resolver -->
  26.     <bean
  27.         class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  28.         <property name="prefix" value="/WEB-INF/view/" />
  29.         <property name="suffix" value=".jsp" />
  30.     </bean>
  31.  
  32.     <!-- Step 1: Define Database DataSource / connection pool -->
  33.     <bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
  34.          destroy-method="close">
  35.         <property name="driverClass" value="org.postgresql.Driver" />
  36.         <property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/rsia_madura" />
  37.         <property name="user" value="postgres" />
  38.         <property name="password" value="postgre" />
  39.  
  40.         <!-- these are connection pool properties for C3P0 -->
  41.         <property name="minPoolSize" value="5" />
  42.         <property name="maxPoolSize" value="20" />
  43.         <property name="maxIdleTime" value="30000" />
  44.     </bean>  
  45.    
  46.     <!-- Step 2: Setup Hibernate session factory -->
  47.     <bean id="sessionFactory"
  48.         class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
  49.         <property name="dataSource" ref="myDataSource" />
  50.         <property name="packagesToScan" value="com.rsia.madura.entity" />
  51.         <property name="hibernateProperties">
  52.            <props>
  53.               <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
  54.               <prop key="hibernate.show_sql">true</prop>
  55.            </props>
  56.         </property>
  57.    </bean>   
  58.  
  59.     <!-- Step 3: Setup Hibernate transaction manager -->
  60.     <bean id="myTransactionManager"
  61.            class="org.springframework.orm.hibernate5.HibernateTransactionManager">
  62.         <property name="sessionFactory" ref="sessionFactory"/>
  63.     </bean>
  64.    
  65.     <!-- Step 4: Enable configuration of transactional behavior based on annotations -->
  66.     <tx:annotation-driven transaction-manager="myTransactionManager" />
  67.  
  68. </beans>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement