[SPRING] Spring xml 설정모음

🐷Jinie (juniorDeveloper)·2020년 12월 9일
1

JSP/MVC/SPRING

목록 보기
77/81
post-thumbnail

1. pom.xml

<!-- ORACLE DRIVER REPOSITORY -->
	<repositories>
		<repository>
			<id>public</id>
			<url>https://repo1.maven.org/maven2/</url>
		</repository>
	</repositories>
<!-- ojdbc8 설정-->
	<dependency>
		<groupId>com.oracle.database.jdbc</groupId>
		<artifactId>ojdbc8</artifactId>
		<version>12.2.0.1</version>
	</dependency>
<!-- Mybatis -->
	<dependency>
		<groupId>org.mybatis</groupId>
		<artifactId>mybatis</artifactId>
		<version>3.3.1</version>
	</dependency>
<!-- Mybatis Spring -->
	<dependency>
		<groupId>org.mybatis</groupId>
		<artifactId>mybatis-spring</artifactId>
		<version>1.2.4</version>
	</dependency>
<!-- Spring JDBC-->
	<dependency>
		<groupId>org.springframework</groupId>
		 <artifactId>spring-JDBC</artifactId>
		 <version>${org.springframework-version}</version>
	</dependency>
	<dependency>
		<groupId>commons-dbcp</groupId>
		<artifactId>commons-dbcp</artifactId>
		<version>1.4</version>
	</dependency>
<!-- 자료실파일업로드 -->
	<dependency>
		<groupId>commons-fileupload</groupId>
		<artifactId>commons-fileupload</artifactId>
		<version>1.3.1</version>
	</dependency>

<!-- AspectJ :AOP -->
	<dependency>
		<groupId>org.aspectj</groupId>
		<artifactId>aspectjrt</artifactId>
		<version>${org.aspectj-version}</version>
	</dependency>
	<dependency>
		<groupId>org.aspectj</groupId>
		<artifactId>aspectjweaver</artifactId>
		<version>1.8.8</version>
	</dependency>	
	<dependency>
		<groupId>org.aspectj</groupId>
		<artifactId>aspectjtools</artifactId>
		<version>${org.aspectj-version}</version>
	</dependency>	
<!-- JPA, 하이버네이트 -->
	  <dependency>
	   <groupId>org.hibernate</groupId>
	   <artifactId>hibernate-entitymanager</artifactId>
	   <version>5.1.0.Final</version>
	  </dependency>
      
	 <dependency>
	   <groupId>org.springframework</groupId>
	   <artifactId>spring-orm</artifactId>
	   <version>${org.springframework-version}</version>
	  </dependency>

<!-- JAVA11이상인경우 JPA사용시추가-->
  <dependency>
	<groupId>javax.xml.bind</groupId>
	<artifactId>jaxb-api</artifactId>
	<version>2.3.0</version>
  </dependency>

2. web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee https://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext.xml</param-value>
	</context-param>
	
<!-- Creates the Spring Container shared by all Servlets and Filters -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	
<!-- Enctype -->
	<filter>
		<filter-name>CharacterEncoding</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>CharacterEncoding</filter-name>
		<url-pattern>*.do</url-pattern>
	</filter-mapping>
<!-- Processes application requests -->
	<servlet>
		<servlet-name>DispatcherServlet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>/WEB-INF/config/presentation-layer.xml</param-value>
		</init-param>
	</servlet>
		
	<servlet-mapping>
		<servlet-name>DispatcherServlet</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>
</web-app>

3. Presentation-layer.xml

<!-- 자료실 사용객체 설정 commonsMultipartResolver-->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />

4. applicationContext.xml

<!-- DataSource 설정하기 -->
<context:property-placeholder location="classpath:config/database.properties" />
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
		<property name="driverClassName" value="${jdbc.driver}" />
		<property name="url" value="${jdbc.url}"/>
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
	</bean>

<!-- Mybatis 설정하기 -->
	<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="configLocation" value="classpath:test-map-Config.xml" />
	</bean>

<!-- Mybatis Template 설정하기 -->
	<bean class="org.mybatis.spring.SqlSessionTemplate">
		<constructor-arg ref="sessionFactory"/>
	</bean>
<!-- JPA 설정하기 -->
  <bean id="jpaVendorAdapter"  class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"></bean>
  
  <bean id ="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
     <property name="dataSource"  ref="dataSource"></property>
     <property name="jpaVendorAdapter"  ref="jpaVendorAdapter"></property>
       <property name="packagesToScan" value="com.springbook.biz"></property>
	  <property name="jpaProperties">
	   <props>
	    <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</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.id.new_generator_mappings">true</prop>
	    <prop key="hibernate.hbm2ddl.auto">update</prop>
	   </props>
	  </property>
  </bean> 

<!--  트랜잭션 설정하기  -->
	<bean  id="txManager"  class="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
	   <property name="dataSource"   ref="dataSource" />
	</bean>
	
	<tx:advice  id="txAdvice"  transaction-manager="txManager" >
		<tx:attributes>
			<tx:method name="get*"  read-only="true" />
			<tx:method name="*" />
		</tx:attributes>
	</tx:advice>
	<aop:config>
		<aop:pointcut id="txPointcut"  expression="execution(* com.psd.biz..ServiceImpl.*(..) )"   />
		<aop:advisor  pointcut-ref="txPointcut"  advice-ref="txAdvice"/>
	</aop:config>

<!-- JDBC Template 설정하기 -->
	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
	    <property name="dataSource" ref="dataSource" />
	</bean>

5. database.properties (오라클기준)

jdbc.driver=oracle.jdbc.OracleDriver
jdbc.url=jdbc:oracle:thin:@//localhost:1521/xe
jdbc.username=system
jdbc.password=1234

6. Mybatis Generator Config File 기본틀

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
                PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
                "http://mybatis.org/dtd/mybatis-3-config.dtd" >
<configuration>
  <typeAliases>
    <typeAlias type="com.psd.biz.member.common.PsdVo"  alias="PsdVo" />
  </typeAliases>
  
  <mappers>
    <mapper resource="mappings/board-mapping.xml" />
  </mappers>
</configuration>
profile
ᴘᴇᴛɪᴛs ᴅᴇ́ᴠᴇʟᴏᴘᴘᴇᴜʀ. ᴘʀᴏɢʀᴀᴍᴍᴀᴛɪᴏɴ = ᴘʟᴀɪsɪʀ 💕

2개의 댓글

comment-user-thumbnail
2020년 12월 29일

안녕하세요. 친절하게 설명해주셔서 공부 정말 잘하고 있는데 질문이 있어서 댓글 남깁니다.
이번에 공부하면서 Spring 5.0이상 버전이 있다는 걸 알게 됬는데 혹시 스프링 환경설정을 하거나 프로젝트를 구성할 때 크게 다른 점이 있을까요? 기왕 공부하는거 최신 버전을 사용해 보고 싶어서요

1개의 답글