ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Spring 설정
    개발 2020. 1. 22. 12:31

     

    1. web.xml 설정

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.1" 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_3_1.xsd">
    
    	<!-- #1. welcome-file 추가 -->
    	<welcome-file-list>
    		<welcome-file>index.jsp</welcome-file>
    	</welcome-file-list>
    
    
    	<!-- #2. application context의 빈관련 설정파일: db등 -->
    	<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>
    			/WEB-INF/spring/root-context.xml
    			<!-- #8.1. Spring Security 관련 설정파일 추가 -->
    			/WEB-INF/spring/security-context.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>
    
    	<!-- #3. appServlet(DispatcherServlet)관련 빈 설정 -->
    	<!-- Processes application requests -->
    	<servlet>
    		<servlet-name>appServlet</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<init-param>
    			<param-name>contextConfigLocation</param-name>
    			<param-value>
    				/WEB-INF/spring/appServlet/servlet-context.xml
    				<!-- #11.1 aop관련 빈설정파일 추가 -->
    				/WEB-INF/spring/appServlet/aspect-context.xml
    				
    			</param-value>
    		</init-param>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    		
    	<servlet-mapping>
    		<servlet-name>appServlet</servlet-name>
    		<url-pattern>/</url-pattern>
    	</servlet-mapping>
    	
    	<!-- #4. post방식 인코딩 설정 UTF-8 필터 -->
    	<filter>
    		<filter-name>encodingFilter</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>encodingFilter</filter-name>
      		<url-pattern>/*</url-pattern>
      	</filter-mapping>
    	
    	<!-- 공용에러페이지 -->
    	<error-page>
    		<location>/WEB-INF/views/common/error.jsp</location>
    	</error-page>
    	
    
    </web-app>
    

     

    2. servlet-context.xml 설정

    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns="http://www.springframework.org/schema/mvc"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:beans="http://www.springframework.org/schema/beans"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xsi:schemaLocation="http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd
    		http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
    		http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
    
    	<!-- #5. appServlet관련 빈설정 : application내에 servlet이 여러개 존재할 수 있다.-->
    	<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
    	
    	<!-- Enables the Spring MVC @Controller programming model -->
    	<annotation-driven />
    
    	<!-- /resource/로 시작하는 요청은 servlet이 처리하지 않고, /resources/폴더의 자원을 제공한다. -->
    	<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    	<resources mapping="/resources/**" location="/resources/" />
    
    	<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    	<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<beans:property name="prefix" value="/WEB-INF/views/" />
    		<beans:property name="suffix" value=".jsp" />
    	</beans:bean>
    	
    	<!-- #14.1 jsonView Bean 및 viewResolver 등록 -->
    	<!-- 요청한 viewName과 실제bean이름을 매핑해주는 BeanNameViewResolver를 사용함. -->
        <!-- bean아이디는 viewResolver로 반드시 지정. 처리순서를 1로 우선처리되도록함. -->
        <beans:bean id="viewResolver" 
        			class="org.springframework.web.servlet.view.BeanNameViewResolver">
            <beans:property name="order" value="1"/>
        </beans:bean>   
    	
    	<beans:bean id="jsonView" 
    				class="net.sf.json.spring.web.servlet.view.JsonView"/>
    	
    	
    	<!-- 스프링컨테이너에 bean 등록 : 
    	지정한패키지를 포함, 하위의 모든 @Component어노테이션이 붙은 클래스를 bean으로 생성 관리함.
    	bean의 이름은 소문자시작하는 클래스명이다.-->
    	<context:component-scan base-package="com.kh.spring" />
    	
    	
    	<!-- #15.1 @Responsebody사용을 위한 의존 : 빈등록 (스프링 5.x.x => MappingJackson2HttpMessageConverter) -->
    	<beans:bean id="jacksonMessageConverter" 
    				class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
    
    
    	<beans:bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
    		<beans:property name="messageConverters">
    			<beans:list>
    				<beans:ref bean="jacksonMessageConverter"/>
                    <beans:bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
    			</beans:list>
    		</beans:property>
    	</beans:bean>
    	
    	
    	<!-- #9. 인터셉터 등록 -->
    	<interceptors>
    		<interceptor>
    			<mapping path="/**"/>
    			<!-- 3.2부터 추가된 기능 exclude-mapping -->
    			<!-- <exclude-mapping path="/admin/**"/> -->
    			<beans:bean id="loggerInterceptor"
    						class="com.kh.spring.common.interceptor.LoggerInterceptor" />		
    		</interceptor>
    		<interceptor>
    			<mapping path="/member/memberView.do"/>
    			<mapping path="/member/memberUpdate.do"/>
    			<mapping path="/board/**/*.do"/>
    			<!-- 스프링3.2부터 추가된 exclude-mapping -->
    			<exclude-mapping path="/board/boardList.do"/>
    			<beans:bean id="loginInterceptor"
    						class="com.kh.spring.common.interceptor.LoginInterceptor"/>
    		</interceptor>
    	</interceptors>
    	
    	
    	<!-- #12.1 파일업로드를 처리할 Resolver클래스 빈등록(빈이름 주의) -->
    	<beans:bean id="multipartResolver" 
    				class="org.springframework.web.multipart.commons.CommonsMultipartResolver">   
    		<beans:property name="maxUploadSize" 
    						value="10485760" /> <!-- max 파일용량은 10MB이다. -->
    	</beans:bean>
    	
    </beans:beans>
    

     

    3. pom.xml 설정

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" 
    		 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
    	<modelVersion>4.0.0</modelVersion>
    	<groupId>com.kh</groupId>
    	<artifactId>spring</artifactId>
    	<name>01_HelloSpring</name>
    	<packaging>war</packaging>
    	<version>1.0.0-BUILD-SNAPSHOT</version>
    	<properties>
    		<java-version>1.8</java-version>
    		<org.springframework-version>5.0.6.RELEASE</org.springframework-version>
    		<org.aspectj-version>1.6.10</org.aspectj-version>
    		<org.slf4j-version>1.6.6</org.slf4j-version>
    	</properties>
    	
    	<!-- #6.1  사설저장소 등록 -->
    	<repositories>
    		<repository>
    			<id>datanucleus-repo</id>
    			<url>http://www.datanucleus.org/downloads/maven2/</url>
    		</repository>
    	</repositories>
    	
    	<dependencies>
    		<!-- Spring -->
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-context</artifactId>
    			<version>${org.springframework-version}</version>
    			<exclusions>
    				<!-- Exclude Commons Logging in favor of SLF4j -->
    				<exclusion>
    					<groupId>commons-logging</groupId>
    					<artifactId>commons-logging</artifactId>
    				 </exclusion>
    			</exclusions>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-webmvc</artifactId>
    			<version>${org.springframework-version}</version>
    		</dependency>
    				
    		<!-- AspectJ -->
    		<dependency>
    			<groupId>org.aspectj</groupId>
    			<artifactId>aspectjrt</artifactId>
    			<version>${org.aspectj-version}</version>
    		</dependency>	
    		<!-- #11. aop처리를 위한 aspectjweaver 추가하기 -->
    		<!-- #13. 트랜잭션 처리를 위한 필수 라이브러리-->
    	    <dependency>
    	        <groupId>org.aspectj</groupId>
    	        <artifactId>aspectjweaver</artifactId>
    	        <version>${org.aspectj-version}</version>
    	    </dependency>
    	    <!-- 스프링3.2이하버젼인 경우, 
    	    	 인터페이스를 구현하지 않은 클래스의 프록시객체를 위한 cglib 추가 -->
    	    <!-- <dependency>
    	        <groupId>cglib</groupId>
    	        <artifactId>cglib</artifactId>
    	        <version>2.2</version>
    	    </dependency> -->
    		
    		<!-- Logging -->
    		<dependency>
    			<groupId>org.slf4j</groupId>
    			<artifactId>slf4j-api</artifactId>
    			<version>${org.slf4j-version}</version>
    		</dependency>
    		<dependency>
    			<groupId>org.slf4j</groupId>
    			<artifactId>jcl-over-slf4j</artifactId>
    			<version>${org.slf4j-version}</version>
    			<scope>runtime</scope>
    		</dependency>
    		<dependency>
    			<groupId>org.slf4j</groupId>
    			<artifactId>slf4j-log4j12</artifactId>
    			<version>${org.slf4j-version}</version>
    			<scope>runtime</scope>
    		</dependency>
    		<dependency>
    			<groupId>log4j</groupId>
    			<artifactId>log4j</artifactId>
    			<version>1.2.15</version>
    			<exclusions>
    				<exclusion>
    					<groupId>javax.mail</groupId>
    					<artifactId>mail</artifactId>
    				</exclusion>
    				<exclusion>
    					<groupId>javax.jms</groupId>
    					<artifactId>jms</artifactId>
    				</exclusion>
    				<exclusion>
    					<groupId>com.sun.jdmk</groupId>
    					<artifactId>jmxtools</artifactId>
    				</exclusion>
    				<exclusion>
    					<groupId>com.sun.jmx</groupId>
    					<artifactId>jmxri</artifactId>
    				</exclusion>
    			</exclusions>
    			<scope>runtime</scope>
    		</dependency>
    
    		<!-- @Inject -->
    		<dependency>
    			<groupId>javax.inject</groupId>
    			<artifactId>javax.inject</artifactId>
    			<version>1</version>
    		</dependency>
    				
    		<!-- Servlet -->
    		<dependency>
    			<groupId>javax.servlet</groupId>
    			<artifactId>javax.servlet-api</artifactId>
    			<version>3.1.0</version>
    			<scope>provided</scope>
    		</dependency>
    		<dependency>
    			<groupId>javax.servlet.jsp</groupId>
    			<artifactId>jsp-api</artifactId>
    			<version>2.1</version>
    			<scope>provided</scope>
    		</dependency>
    		<dependency>
    			<groupId>javax.servlet</groupId>
    			<artifactId>jstl</artifactId>
    			<version>1.2</version>
    		</dependency>
    	
    		<!-- Test -->
    		<dependency>
    			<groupId>junit</groupId>
    			<artifactId>junit</artifactId>
    			<version>4.7</version>
    			<scope>test</scope>
    		</dependency>    
    		
    		<!-- #6. Database 연결관련 의존등록 -->
    		<dependency>
    			<groupId>org.mybatis</groupId>
    			<artifactId>mybatis</artifactId>
    			<version>3.4.6</version>
    		</dependency>
    		<dependency>
    			<groupId>org.mybatis</groupId>
    			<artifactId>mybatis-spring</artifactId>
    			<version>1.3.2</version>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework</groupId>
    			<artifactId>spring-jdbc</artifactId>
    			<version>${org.springframework-version}</version>
    		</dependency>
    		<!-- Database Connection Pool -->
    		<dependency>
    			<groupId>commons-dbcp</groupId>
    			<artifactId>commons-dbcp</artifactId>
    			<version>1.4</version>
    		</dependency>
    		<!-- 사설저장소 사용 (저장소 등록해야함): https://mvnrepository.com/artifact/oracle/ojdbc6  -->
    		<dependency>
    			<groupId>oracle</groupId>
    			<artifactId>ojdbc6</artifactId>
    			<version>11.2.0.3</version>
    		</dependency>
    		
    		
    	    <!-- https://mvnrepository.com/artifact/org.springframework/springloaded -->
    	    <dependency>
    	        <groupId>org.springframework</groupId>
    	        <artifactId>springloaded</artifactId>
    	        <version>1.2.8.RELEASE</version>
    	        <scope>provided</scope>
    	    </dependency>
    		    
    		<!-- #8. 스프링  security 프레임워크 의존 -->
    		<dependency>
    			<groupId>org.springframework.security</groupId>
    			<artifactId>spring-security-core</artifactId>
    			<version>5.0.11.RELEASE</version>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework.security</groupId>
    			<artifactId>spring-security-web</artifactId>
    			<version>5.0.11.RELEASE</version>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework.security</groupId>
    			<artifactId>spring-security-config</artifactId>
    			<version>5.0.11.RELEASE</version>
    		</dependency>
    	
    		
            <!-- #10.query와 resultSet을 logging할 수 있는 log4jdbc-remix 라이브러리추가 -->
    		<!-- https://mvnrepository.com/artifact/org.lazyluke/log4jdbc-remix/0.2.7 -->
    		<dependency>
    			<groupId>org.lazyluke</groupId>
    			<artifactId>log4jdbc-remix</artifactId>
    			<version>0.2.7</version>
    		</dependency>
    		
    		<!-- #12. FileUpload용 라이브러리 추가 -->
    	    <dependency>
    	        <groupId>commons-io</groupId>
    	        <artifactId>commons-io</artifactId>
    	        <version>2.6</version>
    	    </dependency>
    	    <dependency>
    	        <groupId>commons-fileupload</groupId>
    	        <artifactId>commons-fileupload</artifactId>
    	        <version>1.3.3</version>
    	    </dependency>
    	    
    	    
    	    <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
    		<dependency>
    		    <groupId>com.google.code.gson</groupId>
    		    <artifactId>gson</artifactId>
    		    <version>2.8.5</version>
    		</dependency>
    		   
    		   
    		<!-- #14. BeanNameViewResolver: jsonView관련 의존 -->
    	    <dependency>
    	        <groupId>net.sf.json-lib</groupId>
    	        <artifactId>json-lib-ext-spring</artifactId>
    	        <version>1.0.2</version>
    	    </dependency>
    		    
    		    
    		<!-- #15. @Responsebody사용을 위한 의존 : 자바객체->json -->
    	    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
    	    <dependency>
    	        <groupId>com.fasterxml.jackson.core</groupId>
    	        <artifactId>jackson-databind</artifactId>
    	        <version>2.9.5</version>
    	    </dependency>
    			
    	</dependencies>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-eclipse-plugin</artifactId>
                    <version>2.9</version>
                    <configuration>
                        <additionalProjectnatures>
                            <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                        </additionalProjectnatures>
                        <additionalBuildcommands>
                            <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                        </additionalBuildcommands>
                        <downloadSources>true</downloadSources>
                        <downloadJavadocs>true</downloadJavadocs>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.5.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <compilerArgument>-Xlint:all</compilerArgument>
                        <showWarnings>true</showWarnings>
                        <showDeprecation>true</showDeprecation>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.2.1</version>
                    <configuration>
                        <mainClass>org.test.int1.Main</mainClass>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>
    

     

    4. root-context.xml 설정

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:aop="http://www.springframework.org/schema/aop"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
    		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
    		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
    	
    	<!-- Root Context: defines shared resources visible to all other web components -->
    		
    	
    	<!-- #7.1. myBatis(JDBC)설정 연결 설정하기 -->
    	<bean id="realDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    		<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
    		<property name="url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
    		<property name="username" value="spring"/>
    		<property name="password" value="spring"/>
    	</bean>
    
    	<!-- #10.1.log4jdbc-remix 관련 dataSource처리  -->
    	<bean id="dataSource" class="net.sf.log4jdbc.Log4jdbcProxyDataSource">  
    	    <constructor-arg ref="realDataSource" />
    	    <property name="logFormatter">
    	        <bean class="net.sf.log4jdbc.tools.Log4JdbcCustomFormatter">    
    	            <property name="loggingType" value="MULTI_LINE" />
    	            <property name="sqlPrefix" value="[SQL] " />
    	        </bean>
    	    </property>
    	</bean>
    
    	
    	<!-- #7.2. myBatis(JDBC)설정 : SqlSessionFactory -->
    	<bean id="sqlSessionFactoryBean" 
    		  class="org.mybatis.spring.SqlSessionFactoryBean">
    		<!-- name=dataSource => 빈객체sqlSessionFactoryBean의  property명 dataSource임(setter) -->
    		<!-- ref의 dataSource는 위에서 선언한 datasource 빈객체를 의미함. -->
    		<property name="dataSource" ref="dataSource"/>
    		
    		<!-- 앞으로 생성할 모든 mapper파일을 한번에 읽어오도록하자. -->
    		<!-- 여기서 classpath는 target/classes를 의미한다.-->
    		<!-- src/main/resources 디렉토리에서 작성된 파일들은 classpath로 이동함.-->
    		<property name="mapperLocations" value="classpath*:mapper/**/*.xml"/>
    		
    		<!-- mybatis-config.xml파일 위치를 명시함. -->
    		<property name="configLocation" value="classpath:mybatis-config.xml"/>
    	</bean>
    	
    	<!-- #7.3. SqlSessionTemplate 마이바티스 스프링 연동모듈의 핵심기능. -->
    	<!-- SqlSessionTemplate : SqlSession 인터페이스를 구현클래스-->
    	<!-- 여러 dao에서 공유하므로 메모리관리에 있어 최적화된 테크닉. -->
    	<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
    		<constructor-arg index="0" ref="sqlSessionFactoryBean"/>
    	</bean>
    	
    	
    	<!-- #13.1. 트랜잭션 처리를 위한 트랜잭션매니저 설정해야 한다. -->
    	<bean id="transactionManager" 
    		  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    		<property name="dataSource" ref="dataSource" />
    	</bean>
    
    	<!-- #13.2. @Transactional이 붙은 메소드를 대상으로 Transaction Advice를 적용함. -->
    	<!-- <tx:annotation-driven transaction-manager="transactionManager" /> -->
    	
    	<!-- ################ 선언적 방식의 트랜잭션 시작 #################### -->
    	<!-- #13.2. 선언적방식의 트랜잭션처리 -->
    	<tx:advice id="txAdvice" transaction-manager="transactionManager">
    		<tx:attributes>
    			<tx:method name="select*" rollback-for="Exception" 
    									  read-only="true"/>
    			<tx:method name="insert*" rollback-for="Exception"/>
    			<tx:method name="update*" rollback-for="Exception"/>
    			<tx:method name="delete*" rollback-for="Exception"/>
    		</tx:attributes>
    	</tx:advice>
    
    	<!-- #13.3 선언적방식의 트랜잭션 : aop pointcut및 advice등록 -->
    	<aop:config proxy-target-class="true">
    		<aop:pointcut id="serviceMethod" 
    					  expression="execution(* com.kh.spring..*ServiceImpl.*(..)))"/>
    		<aop:advisor id="transactionAdvisor" 
    					 advice-ref="txAdvice" 
    					 pointcut-ref="serviceMethod"/>
    	</aop:config>
    	<!-- ################ 선언적 방식의 트랜잭션 끝 #################### -->
    	
    	
    	
    </beans>
    

     

     

    5. log4j.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
    <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    
    	<!-- Appenders -->
    	<!-- Logger출력을 처리하는 객체 -->
    	<!-- 
    		패턴 레이아웃 설명
    		[PatternLayout API](https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html)
    		
    		
    		* %c : 카테고리명(logger이름)을 표시
    			* 카테고리명이 a.b.c일때, %c{2}는 b.c를 출력
    		* %C : 클래스명을 표시함.	
    			* 풀 클래스 명이 com.kh.logger일때, %C{2}는 kh.logger를 출력
    		* %d : 로그 시간을 출력한다. java.text.SimpleDateFormat에서 적절한 출력 포맷을 지정할 수 있다. 
    			* %d{HH:mm:ss, SSS}
    			* %d{yyyy MMM dd HH:mm:ss, SSS}
    			* %d{ABSOLUTE} 
    			* %d{DATE} 
    			* %d{ISO8601}
    		* %F : 파일명을 출력. 로그시 수행한 메소드, 라인번호가 함께 출력된다.
    		* %l : 로깅이 발생한 caller의 위치정보. 자바파일명:라인번호(링크제공) 
    		* %L : 라인 번호만 출력한다(링크없음)
    		* %m : 로그로 전달된 메시지를 출력한다.
    		* %M : 로그를 수행한 메소드명을 출력한다. 
    		* %n : 플랫폼 종속적인 개행문자가 출력. rn 또는 n
    		* %p : 로그 이벤트명등의 priority 가 출력(debug, info, warn, error, fatal )
    		* %r : 로그 처리시간 (milliseconds)
    		* %t : 로그이벤트가 발생된 쓰레드의 이름을 출력
    		* %% : % 표시를 출력. escaping
    		* %r : 어플리케이션 시작 이후 부터 로깅이 발생한 시점의 시간(milliseconds)
    		* %X : 로깅이 발생한 thread와 관련된 MDC(mapped diagnostic context)를 출력합니다. %X{key} 형태.
    	
    	
    	 -->
    	<appender name="console" class="org.apache.log4j.ConsoleAppender">
    		<param name="Target" value="System.out" />
    		<layout class="org.apache.log4j.PatternLayout">
    			<!-- <param name="ConversionPattern" value="%-5p: %c - %m%n" /> -->
    			<!-- <param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss}] %-5p: [ %l ] - %m%n" /> -->
    			<param name="ConversionPattern" value="%-5p: [ %l ] - %m%n" />
    		</layout>
    	</appender>
    	
    	<appender name="systemLogger" 
    			  class="org.apache.log4j.DailyRollingFileAppender">
    		<param name="file" 
    			   value="${catalina.base}/logs/spring/helloSpring.log"/>
    		<param name="Append" value="true"/>
    		<param name="datePattern" value=".yyyy-MM-dd"/>
    		<layout class="org.apache.log4j.PatternLayout">
    			<param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss}] %-5p: [ %l ] - %m%n" />
    		</layout>
    	</appender>
    	
    	<!-- #10.2.log4jdbc-remix 로그 출력 appender 추가 -->
    	<appender name="sqlLogger" class="org.apache.log4j.ConsoleAppender">
    		<layout class="org.apache.log4j.PatternLayout">
    			<param name="ConversionPattern" value="%-5p: %m%n" />
    		</layout>
    	</appender>
    
        <!-- #10.3.log4jdbc-remix 관련 logger 시작 -->
    	<!-- Query Loggers  -->
    	<logger name="jdbc.sqlonly" additivity="false">
    		<level value="INFO" />
    		<appender-ref ref="sqlLogger"/>
    	</logger>
    	<logger name="jdbc.resultsettable" additivity="false">
    		<level value="debug" />
    		<appender-ref ref="sqlLogger"/>
    	</logger>
    	
    	
    	
    	<!-- Application Loggers -->
    	<logger name="com.kh.spring" additivity="true">
    		<level value="debug" />
    		<!-- <appender-ref ref="console"/> -->
    	</logger>
    	
    	<!-- 3rdparty Loggers -->
    	<logger name="org.springframework.core">
    		<level value="info" />
    	</logger>
    	
    	<logger name="org.springframework.beans">
    		<level value="info" />
    	</logger>
    	
    	<logger name="org.springframework.context">
    		<level value="info" />
    	</logger>
    
    	<logger name="org.springframework.web">
    		<level value="info" />
    	</logger>
    
    	<!-- Root Logger -->
    	<root>
    		<priority value="warn" />
    		<appender-ref ref="console" />
    		<appender-ref ref="systemLogger" />
    	</root>
    	
    </log4j:configuration>
    

     

     

    6. aspect-context.xml 설정

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:aop="http://www.springframework.org/schema/aop"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
    	
    	<!-- #11.2. aop 관련태그작성-->            
    	<!--==================== XML 선언적 AOP의 활용 시작 ====================-->
    	<!-- LoggerAspect 빈등록 -->
    	<!-- <bean id="loggerAspect" 
    		  class="com.kh.spring.common.aop.LoggerAspect"/>
    	
    	<aop:config>
    	    <aop:aspect id="loggerAspect" ref="loggerAspect">
    	        <aop:pointcut expression="execution(* com.kh.spring.memo..*(..))" 
    	        			  id="pcForAll"/>
    	        <aop:around method="loggerAdvice" pointcut-ref="pcForAll"/>
    	    </aop:aspect>
    	</aop:config> -->
    	
    	<!--==================== XML 선언적 AOP의 활용 끝 ====================-->
    
    	<!--==================== 어노테이션방식 AOP의 활용 시작 ====================-->
    	<!-- root-context scope에 설정된 트랜잭션관리자 빈 설정을 그대로 가져와 적용시켜줌 -->
    	<aop:aspectj-autoproxy />
    	<!--==================== 어노테이션방식 AOP의 활용 끝 ====================-->
    
    
    </beans>
    

    '개발' 카테고리의 다른 글

    협업도구와 친해지기 [ STS 와 Git + 소스트리 활용 ]  (6) 2020.01.28
    Spring Framework 와 친해지기  (0) 2020.01.17
    TDD와 친해지기  (0) 2020.01.17
    안녕하세요  (0) 2020.01.16

    댓글

Designed by Tistory.