Spring 초 입 설정 ~ 13
1SpringMVC 설정 의 대체 방안 (이 방안 은 servlet 3.0 이상 버 전)
1. DispatcherServlet
customizeRegistration() , AbstractAnnotationConfigDispatcherServletInitializer dispachServlet customizeRegistration() 。 。
2. Servlet filter
java initializer , 。 , , Spring WebApplicationInitializer 。
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;
import org.springframework.web.WebApplicationInitializer;
public class TestServlet implements WebApplicationInitializer {
public void onStartup(ServletContext servletContext) throws ServletException {
/** Servlet*/
Dynamic testServlet=servletContext.addServlet("myServlet",(Class extends Servlet>) MyTest.class);
testServlet.addMapping("/custom/***"); // Servlet
}
}
위의 코드 는 간단 합 니 다. servlet 를 등록 하고 하나의 경로 에 비 추 는 것 입 니 다. 물론 디 스 패 치 Servlet 에 도 비 출 수 있 습 니 다.이와 유사 한 우 리 는 테크네튬 방식 으로 Listener 와 filter 의 방식 으로 등록 할 수 있다.
import javax.servlet.Filter;
import javax.servlet.FilterRegistration.Dynamic;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.springframework.web.WebApplicationInitializer;
public void onStartup(ServletContext servletContext) throws ServletException {
Dynamic filter=servletContext.addFilter("myFilter", (Class extends Filter>) MyTest.class);
/** null dispatcher false */
filter.addMappingForUrlPatterns(null,false, "/custom/**");
}
이 방식 은 Servlet 용기 에 적합 합 니 다. 프로젝트 에 속 하 는 항목 이 이 용기 보다 낮 으 면 웹. xm 에서 설정 해 야 합 니 다.
contextConfigLocation
/WEB-INF/spring/root-context.xml
org.springframework.web.context.ContextLoaderLister
appServlet
org.springframwork.web.servlet.DispatcherServlet
1
appServlet
/
저 희 는 xml 에서 설정 한 후에 설정 파일 에 따라 위아래 질문 정 보 를 읽 습 니 다.
이것 은 설정 파일 로 불 러 오고 설정 파일 로 불 러 올 수 있 습 니 다. 주석 @ Configuration 주석 클래스 에서 설정 을 불 러 옵 니 다. 설정 파일 웹. xml 을 다시 고 쳐 야 할 수도 있 습 니 다.
contextClass
org.springframework.web.context.support.AnnotationConfigWebapplicationContext
contextConfigLocation
com.textSpring.Spilter
org.springframework.web.context.ContextLoaderLister
appServlet
org.springframwork.web.servlet.DispatcherServlet
contextClass
org.springframework.web.context.support.AnnotationConfigWebapplicationContext
contextConfigLocation
com.textSpring.Spilter
1
appServlet
/
여기 서 우리 가 설정 한 웹. xml 과 처음에 설정 한 웹. xml 은 바로 여기 서 시작 하 는 자바 류 를 직접 설정 하여 dispatcher Servlet 를 시작 하 는 것 입 니 다. 우 리 는 여기 서 init 를 사용 해 야 합 니 다.param 탭 은 위 에 설 정 된 context - param 의 파일 을 자바 클래스 로 설정 합 니 다.다른 것 은 기본적으로 같다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.