티스토리 뷰

1.스프링과 스프링 MVC

스프링이란

스프링은 자바 응용 프로그램을 신속하게 개발하는 데 널리 사용되는 오픈 소스 프레임워크입니다. 
보통은 스프링이라고 하지만 정환학 표현은 스프링 프레임워크 입니다.
스프링은 특정 클래스에 대한 수직적인 흐름뿐만 아니라 수평적 처리까지 가능 가능해서 더욱 좋습니다. 
스프링은 의존성 주입이나 관점 지향 프로그래밍과 같은 기능뿐만 아니라 기본적으로 웹을 개발할 수 있는 웹 
MVC 프레임워크도 함께 제공합니다.

스프링의 주요 특징
일반적인 자바 객체를 위한 POJO지원
객체 간 결합도를 줄이는 의존성 주입 지원
공통 모듈을 재사용하는 AOP 지원
일관성 있는 모듈의 트랜잭션 지원

스프링MVC

스프링MVC

스프링 MVC는 스프링이 제공하는 웹 애플리케이션 개발 전용 프레임워크로, MVC-뷰-컨트롤러 패턴을 사용합니다. 스프링 MVX를 이용해 웹 애플리케이션의 모델, 뷰, 컨트롤러 사이의 의존 관계를 스프링 컨테이너가 관리하고 스프링이 제공하는 많은 기능을 자유롭게 확장해 웹 애플리케이션을 구축할 수 있습니다.

스프링 MVC의 구성 요소

스프링 MVC는 웹 브라우저에서 서버로 들어오는 모든 웹 요청을 받아 처리하고, 결과를 되돌려 주기까지 디스패처 서블릿의 도움을 받습니다. 디스패처 서블릿은 웹 애플리케이션으로 들어오는 모든 요청을 제어해 모델 - 뷰 - 컨트롤러 를 조합해 웹 브라우저에 출력하는 클래스로, 스프링 MVC의 대표적인 구성 요소입니다.

 

2.스프링 MVC 개발환경 설정

1.
maven repository 검색 후 검색 창에 jstl 검색 - 사용자가 제일 많은 JSTL을 클릭 .

2.
1.2를 클릭.

3.
Maven을 클릭 후에 나타나는 명령어들을 복사.

4.web.xml에 복사를 붙여넣는다.

5. 
저장을 위해 Alt+F5를 누른뒤 해당 프로젝트를 체크하고, OK를 누른다.

6.
OK를 누른 후에는 webapp폴더 안에 index.jsp 파일이 생성이 되어 있다.

7.해당 문구를 추가해준다.

8.
사진처럼 버전에 맞게 넣어준다.

9.

아래 명령어들 <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>

<!-- 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>

 

 

<?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">

 

<!-- 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</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>

 

<!-- 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>

<load-on-startup>1</load-on-startup>

</servlet>

 

<servlet-mapping>

<servlet-name>appServlet</servlet-name>

<url-pattern>/</url-pattern>

</servlet-mapping>

</web-app>

 

 

<!DOCTYPE&nbsp;log4j:configuration&nbsp;SYSTEM&nbsp;" http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd ">

 

'정리 노트 > Spring' 카테고리의 다른 글

Spring Chapter7 [15-5]  (0) 2024.01.19
Spring Chapter5~Chapter6 [15-4]  (0) 2024.01.18
Spring Chapter4~Chapter5 [15-3]  (0) 2024.01.17
Spring Chapter3 [15-2]  (0) 2024.01.16
Spring 환경 구축[14-5]  (0) 2024.01.12
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함