오봉이와 함께하는 개발 블로그
IntelliJ에서 SpringMVC 프로젝트 생성 본문
728x90
환경
- Mac OS Big Sur 11.6.1
- x86 아키텍쳐
- IntelliJ Ultimate
- openjdk 11 사용
방법
- https://mazdah.tistory.com/880 님의 글 참조
- Maven 프로젝트 생성
- 프로젝트 우클릭 후 Add FrameWork Support 에서 springMVC 추가
- 다음과 같이 경로 변경
- servlet-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
<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>
<context:component-scan base-package="controller" />
</beans:beans>
- 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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>
- web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>
<load-on-startup>1</load-on-startup>
</servlet>
<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>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
- cmd + ; 로 Project Structure 열기
- Modules 에서 Spring 클릭 후 context 추가
- Modules 에서 Spring 클릭 후 context 추가
- web 클릭 후 Deployment Descriptor에는 web,xml의 경로가, 하단의 Web Resource Directories에는 webapp 디렉토리가 정상적으로 설정되어 있는지 확인
- Artifacts에서 라이브러리 추가
- 마지막으로 톰캣 설정
728x90
'BE > Spring' 카테고리의 다른 글
Spring - IntelliJ MySQL&MyBatis 연동 오류 해결 (0) | 2022.01.10 |
---|---|
Spring - IntelliJ MyBatis 연동 (0) | 2022.01.07 |
Spring - Controller와 요청 처리 (0) | 2022.01.07 |
Spring - 모델 패턴 (0) | 2022.01.06 |
Spring - AOP 간단한 기초 설명 (0) | 2022.01.05 |
Comments