当前位置:网站首页>Annotations simplify configuration and loading at startup
Annotations simplify configuration and loading at startup
2022-07-03 08:38:00 【The corner of fufu】
Catalog
One 、 Annotations simplify configuration
Annotations are used to simplify Web Application configuration process
In the face of multiple Web Applications , If you use web.xml Heavy workload , So we can use annotations
Servlet Core notes :@WebServlet
java page
package com.imooc.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/anno")
public class AnnotationServlet extends HttpServlet{
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().println("I'm annotation servlet!");
}
}
It uses @WebServlet("/anno")
And in web.xml Using the following code in has the same effect
<servlet>
<servlet-name>anno</servlet-name>
<servlet-class>com.imooc.servlet.AnnotationServlet</servlet-class>
</servlet>
<!-- take Servlet And URL binding -->
<servlet-mapping>
<servlet-name>anno</servlet-name>
<url-pattern>/anno</url-pattern>
</servlet-mapping>
Two 、 Load on startup
- web.xml Use <load-on-startup> Set startup load
- Loading at startup is often used for system preprocessing in work
1.java page
This project is to create a database , Import and analyze
ImportServlet.java
package com.ssyt.servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
public class CreateServlet extends HttpServlet{
@Override
public void init() throws ServletException {
System.out.println(" Creating database ");
}
}
CreateServlet.java
package com.ssyt.servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
public class ImportServlet extends HttpServlet{
@Override
public void init() throws ServletException {
System.out.println(" Importing build data ");
}
}
AnalysisServlet.java
package com.ssyt.servlet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
@WebServlet(urlPatterns="/unused",loadOnStartup=2)
public class AnalysisServlet extends HttpServlet{
@Override
public void init() throws ServletException {
System.out.println(" Analyzing results ");
}
}
2.web.xml The configuration file
<servlet>
<servlet-name>create</servlet-name>
<servlet-class>com.ssyt.servlet.CreateServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet>
<servlet-name>import</servlet-name>
<servlet-class>com.ssyt.servlet.ImportServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
- Among them in web.xml in :0~9999 Indicates the sequence of loading at startup
<load-on-startup>1</load-on-startup>
- stay java Pages use annotations to simplify configuration : among url Must be written
@WebServlet(urlPatterns="/unused",loadOnStartup=2)
3. Load on startup
No request made , Load on startup , Start in sequence
边栏推荐
猜你喜欢
Display terrain database on osgearth ball
Gradle's method of dynamically modifying APK package name
【云原生】微服务之Feign的介绍与使用
分配异常的servlet
单调栈-84. 柱状图中最大的矩形
Jupyter remote server configuration and server startup
[concurrent programming] Table hopping and blocking queue
100 GIS practical application cases (78) - Multi compliance database design and data warehousing
VIM learning notes from introduction to silk skating
Collection interface
随机推荐
【Rust 笔记】11-实用特型
分配异常的servlet
Explain sizeof, strlen, pointer, array and other combination questions in detail
Notes on understanding applets 2022/7/3
Advanced OSG collision detection
Markdown directory generation
Unity editor expansion - controls, layouts
MySQL 8
redis集群系列四
jupyter远程服务器配置以及服务器开机自启
Development material set
Conversion between golang JSON format and structure
[rust notes] 12 closure
【Rust笔记】06-包和模块
Clion toolchains are not configured configure disable profile problem solving
Introduction to Base64 coding
Ue5 opencv plug-in use
Unity interactive water ripple post-treatment
【云原生】微服务之Feign的介绍与使用
Osganimation library parsing