1. 해당 톰캣 설치된 폴더로 이동

2. logs -> catalina.out 확인

3. 오류가 적혀있다... 나의 오류는

  ---> mysql 커넥터를 내 로컬 톰캣에 넣고 썼는데 프로젝트에 커넥터를 넣지 않았던 것.

  ---> 배포 서버 톰캣의 lib에는 mysql 커넥터가 없었다

  ---> 배포 서버 톰캣에 커넥터를 넣거나 프로젝트에 커넥터를 넣어서 해결..!

 

허무하게 해결

'spring' 카테고리의 다른 글

[스프링] 에러페이지 만들기  (0) 2021.04.29
[스프링] 프로젝트 초기 설정 하기  (0) 2021.04.29

1. 에러를 처리할 패키지 생성

2. 에러 처리할 파일 작성

package <-- 1에서 만든 패키지-->;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import lombok.extern.log4j.Log4j;

@ControllerAdvice
@Log4j
public class CommonExceptionAdvice {
	
	@ExceptionHandler(Exception.class)
	public String exception(Exception exception, Model model) {
		log.error(exception.getMessage()); //콘솔에서 로그 확인
		return "error_page"; //해당 에러페이지 출력
	}
}

3. servlet-context.xml에서 스캔하도록 추가

<context:component-scan base-package="<-- 해당 에러 패키지-->"/>

** 404의 경우

1. web.xml 수정(throwExceptionIfNoHandlerFound 추가)

	<!-- 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</param-value>
		</init-param>
		<init-param>
			<param-name>throwExceptionIfNoHandlerFound</param-name>
			<param-value>true</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>

2. 에러 처리 파일에 메소드 추가

	@ExceptionHandler(NoHandlerFoundException.class)
	@ResponseStatus(HttpStatus.NOT_FOUND)
	public String handle404(NoHandlerFoundException exception) {
		return "error_page";
	}

 

1. 스프링 mvc 프로젝트 생성

2. pom.xml 수정

2-1. 자바버전 및 스프링 프레임워크 버전 수정(자바버전, 스프링프레임워크버전)

<properties>
		<java-version>1.8</java-version>
		<org.springframework-version>5.0.7.RELEASE</org.springframework-version>
		<org.aspectj-version>1.6.10</org.aspectj-version>
		<org.slf4j-version>1.6.6</org.slf4j-version>
</properties>

2-2. 메이븐 컴파일러 플러그인 변경(버전, 소스, 타겟)

	<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArgument>-Xlint:all</compilerArgument>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>

2-3. 스프링 테스트(버전은 현재 스프링에 맞추기), 롬복 추가, log4j 버전 수정, 런타임 수정

		<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>${org.springframework-version}</version>
			<scope>test</scope>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<version>1.18.0</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.17</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>

2-4. jnuit 버전 수정

		<!-- Test -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
			<scope>test</scope>
		</dependency>

* import org.junit cannot be resolved 오류 : property -> Java build path -> Libraries -> Add Libraries -> Junit

 

2-5. HikariCP 추가

<!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
<dependency>
    <groupId>com.zaxxer</groupId>
    <artifactId>HikariCP</artifactId>
    <version>2.7.4</version>
</dependency>

2-6. mybatis, mybatis-spring, spring-jdbc, spring-tx 추가

<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis</artifactId>
    <version>3.4.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis-spring</artifactId>
    <version>1.3.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
    <version>5.0.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>5.0.7.RELEASE</version>
</dependency>

2-7. log4jdbc-log4j2 추가(sql 로그 확인용도)

<!-- https://mvnrepository.com/artifact/org.bgee.log4jdbc-log4j2/log4jdbc-log4j2-jdbc4 -->
<dependency>
    <groupId>org.bgee.log4jdbc-log4j2</groupId>
    <artifactId>log4jdbc-log4j2-jdbc4</artifactId>
    <version>1.16</version>
</dependency>

2-8. servlet 버전 업(기존 버전 주석 후 추가함)

		<!-- Servlet -->
		<!-- <dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>servlet-api</artifactId>
			<version>2.5</version>
			<scope>provided</scope>
		</dependency> -->
		<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
		<dependency>
		    <groupId>javax.servlet</groupId>
		    <artifactId>javax.servlet-api</artifactId>
		    <version>3.1.0</version>
		    <scope>provided</scope>
		</dependency>

2-9. json 데이터 처리 위해 jackson-databind 추가

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.9.4</version>
</dependency>

2-10. 파일 업로드위해 commons-fileupload 추가

<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.3.3</version>
</dependency>

 

3. root-context.xml 수정

3-1. HicariConfig, dataSource 추가

	<!-- HicariCP configuration -->
	<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
				
		<property name="driverClassName" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy"></property>
		<property name="jdbcUrl" value="jdbc:log4jdbc:mysql://경로/스키마?useSSL=false&amp;serverTimezone=UTC"></property>
		<property name="username" value="계정명"></property>
		<property name="password" value="비밀번호"></property>
	</bean>
	
	<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
		<constructor-arg ref="hikariConfig"></constructor-arg>
	</bean>

3-2. mybatis sql Session Factory Bean 추가(+필요시 mybatis config 추가)

	<!-- MyBatis SqlSessionFactoryBean -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource"></property>
		<property name="configLocation" value="classpath:/mybatis-config.xml"></property>
	</bean>

* 어노테이션을 이용하여 마이바티스를 사용할 때 해당 매퍼 패키지를 스캔하는 것을 추가

<mybatis-spring:scan base-package="해당매퍼패키지"/>

* mybatis-config.xml은 src/main/resources 하위에 위치

* DB의 컬럼과 vo, dto를 연동하기 위한 옵션 추가함

<?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>
    <settings>        
        <!-- 전통적 DB 컬럼명을 JAVA의 Camel표기법으로 자동 매핑 설정 -->
        <setting name="mapUnderscoreToCamelCase" value="true"/>						
    </settings>    	
    
</configuration>

 

+ Recent posts