|
다음 판
|
이전 판
|
wiki:spring:jap [2020/12/16 09:34] hylee 만듦 |
— (현재) |
| ====== 클립보드_복사 ====== | |
| <WRAP left notice 80%> | |
| * description : | |
| * author : 도봉산핵주먹 | |
| * email : hylee@repia.com | |
| * lastupdate : 2020-12-16 | |
| </WRAP> | |
| <WRAP clear/> | |
| |
| ===== Spring에 JAP 적용하기 ===== | |
| |
| |
| |
| ===== 적용파일 목록 ===== | |
| |
| * context-hibernate.xml | |
| * context-jpa-respository.xml | |
| |
| |
| ===== context-hibernate.xml ===== | |
| |
| > Tip | |
| |
| 아래 코드에서 두개만 고치면 된다. \\ | |
| |
| ''<property name="dataSource" ref="" />'' -> context-datasource.xml 에 JPA로 사용할 DB정보의 bean ID \\ | |
| ''<property name="packagesToScan" value="" >'' -> values는 패키지 정보를 입력 | |
| \\ | |
| \\ | |
| <code xml> | |
| |
| <?xml version="1.0" encoding="utf-8"?> | |
| <beans xmlns="http://www.springframework.org/schema/beans" | |
| xmlns:context="http://www.springframework.org/schema/context" | |
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd | |
| http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> | |
| | |
| <!-- 컨테이너가 관리하는 EntityManager 생성, @PersistenceContext와 함께 사용 --> | |
| <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> | |
| <property name="dataSource" ref="egov.dataSource" /> | |
| <!-- 어노테이션 매핑정보 스캔 --> | |
| <property name="packagesToScan" value="com" /> | |
| <!-- 구현체별 자체 기능을 표준화 --> | |
| <property name="jpaVendorAdapter"> | |
| <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> | |
| <property name="showSql" value="true" /> | |
| <property name="generateDdl" value="true" /> | |
| </bean> | |
| </property> | |
| <!-- persistence.xml 설정정보와 함께 사용가능 --> | |
| <property name="jpaProperties"> | |
| <props> | |
| <!-- <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.EJB3NamingStrategy</prop> --> | |
| <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop> | |
| <!-- hibernate 5 버전에서의 세팅 (4 버전은 위에껄 사용)- | |
| <prop key="hibernate.naming.implicit-strategy">org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl</prop> | |
| <prop key="hibernate.naming.physical-strategy">org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl</prop> | |
| --> | |
| <prop key="hibernate.hbm2ddl.auto">validate</prop> | |
| <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop> | |
| <prop key="hibernate.show_sql">true</prop> | |
| <prop key="hibernate.format_sql">true</prop> | |
| <prop key="hibernate.use_sql_comments">true</prop> | |
| <prop key="hibernate.jdbc.batch_size">5</prop> | |
| </props> | |
| </property> | |
| </bean> | |
| | |
| </beans> | |
| |
| |
| |
| </code> | |
| |
| |
| ===== context-jpa-respository.xml ===== | |
| |
| > Tip | |
| |
| 아래 코드에서 한개만 고치면 된다. \\ | |
| |
| ''<jpa:repositories base-package="">'' -> base-package="" 는 패키지 정보 입력\\ | |
| \\ | |
| \\ | |
| <code xml> | |
| |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <beans xmlns="http://www.springframework.org/schema/beans" | |
| xmlns:jpa="http://www.springframework.org/schema/data/jpa" | |
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd | |
| http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"> | |
| |
| <jpa:repositories base-package="com"></jpa:repositories> | |
| |
| </beans> | |
| |
| |
| </code> | |
| |
| |
| ===== POM.xml ===== | |
| |
| <code xml> | |
| |
| <properties> | |
| <egovframework.jpa.version>3.7.0</egovframework.jpa.version> | |
| <hibernate.version>4.3.11.Final</hibernate.version> | |
| </properties> | |
| <dependencies> | |
| <dependency> | |
| <groupId>egovframework.rte</groupId> | |
| <artifactId>egovframework.rte.psl.data.jpa</artifactId> | |
| <version>${egovframework.jpa.version}</version> | |
| </dependency> | |
| |
| <!-- Hibernate --> | |
| <dependency> | |
| <groupId>org.hibernate</groupId> | |
| <artifactId>hibernate-core</artifactId> | |
| <version>${hibernate.version}</version> | |
| </dependency> | |
| |
| <dependency> | |
| <groupId>org.hibernate</groupId> | |
| <artifactId>hibernate-validator</artifactId> | |
| <version>5.4.2.Final</version> | |
| </dependency> | |
| <dependency> | |
| <groupId>org.springframework.data</groupId> | |
| <artifactId>spring-data-jpa</artifactId> | |
| <version>1.11.10.RELEASE</version> | |
| <exclusions> | |
| <exclusion> | |
| <groupId>org.slf4j</groupId> | |
| <artifactId>slf4j-api</artifactId> | |
| </exclusion> | |
| <exclusion> | |
| <groupId>org.slf4j</groupId> | |
| <artifactId>jcl-over-slf4j</artifactId> | |
| </exclusion> | |
| </exclusions> | |
| </dependency> | |
| </dependencies> | |
| |
| </code> | |
| |
| |
| |
| | |
| {{tag>도봉산핵주먹 spring jpa}} | |