Advertisement
ahmadsm

conton koneksi ke database postgresql

Sep 24th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 4.30 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" xmlns:context="http://www.springframework.org/schema/context"
  4.       xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
  5.       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
  6.       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  7.       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
  8.       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
  9.                http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
  10.                http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
  11.  
  12.     <context:annotation-config />
  13.     <!-- Sesuaikan dengan nama package dao (data access object) yang telah dibuat atau mau dibuat -->
  14.     <context:component-scan base-package="com.asm.dao" />
  15.    
  16.     <!-- Local Database -->  
  17.     <bean id="dsSPA" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  18.         <property name="driverClassName" value="org.postgresql.Driver" />
  19.         <property name="url" value="jdbc:postgresql://172.168.100.10:5436/db_SampleProjectSpringHibernate" />  
  20.         <property name="username" value="postgres"/>
  21.         <property name="password" value="postgres"/>            
  22.     </bean>
  23.     <bean id="entityManagerFactoryInternal" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  24.         <property name="dataSource" ref="dsSPA"/>
  25.         <property name="loadTimeWeaver">
  26.             <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
  27.         </property>
  28.         <!-- Sesuaikan dengan nama package entity  yang telah atau mau dibuat -->
  29.         <property name="packagesToScan" value="com.asm.entity"/>
  30.         <property name="jpaVendorAdapter">
  31.             <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
  32.                 <property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect" />
  33.                 <!-- showsql = true sama dengan menampilkan sql atau query di log-->
  34.                 <property name="showSql" value="true" />
  35.                 <!-- generateddl= true  sama dengan create tables and fields in database (syarat database sudah tersedia, otomatis generate tabel dan column)-->
  36.                 <property name="generateDdl" value="true" />
  37.             </bean>
  38.         </property>
  39.         <property name="jpaProperties">
  40.             <props>
  41.                 <prop key="hibernate.format_sql">true</prop>
  42.             </props>
  43.         </property>
  44.     </bean>
  45.     <!-- transactionManagerInternal biasa dipakai buat aksi simpan, ubah, hapus, cari dll
  46.                contoh :
  47.                @Transactional(value = "transactionManagerInternal")
  48.                public void save(BusPendaftaran data) {
  49.                em.persist(data);
  50.                }
  51.  
  52.                @Transactional(value = "transactionManagerInternal")
  53.                public void update(BusPendaftaran data) {
  54.                em.merge(data);
  55.                }
  56.        -->
  57.     <bean id="transactionManagerInternal" class="org.springframework.orm.jpa.JpaTransactionManager">
  58.         <property name="entityManagerFactory" ref="entityManagerFactoryInternal"/>
  59.         <property name="jpaDialect">
  60.             <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
  61.         </property>
  62.     </bean>
  63.     <!-- sharedEntityManagerInternal = (Resource / EntityManager)
  64.                contoh :
  65.                @Resource(name = "sharedEntityManagerInternal")
  66.                private EntityManager em;
  67.        -->
  68.     <bean id="sharedEntityManagerInternal" name="sharedEntityManagerInternal" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
  69.         <property name = "entityManagerFactory" ref="entityManagerFactoryInternal"/>
  70.     </bean>
  71.     <tx:annotation-driven transaction-manager="transactionManagerInternal" />
  72. </beans>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement