由于某些缘故,公司的产品需要升级,但并不希望花费大量时间重写前端代码(原来的就不是前后分离的)。所以虽然spring和springboot都升级为最新的版本,但是依然还是需要支持jsp,并继续用打包为war。

本文中的例子百分百可以执行。

一、概述

升级的理由:

  1. java1.8已经用得太久了,就快不是长期优先支持的。毕竟1.8已经用了快10年了,该抛弃了
  2. java17,对于性能的提升是明显的,至少有关资料是这么说的,其次是被优先支持的
  3. 有关三方技术也渐渐转向jdk17了,例如VSCODE,KAFKA。eclise,sts也不再优先支持1.8
  4. 团队需要升级技术,不能老是在1.8中打转
  5. spring5.x已经用太久了,而且有不少缺点;原来的诸多配置需要多个xml文件,有点小繁琐。
  6. 其它理由
  7. 老版本的产品依然继续支持

保持war包理由:

  1. 每次更新的时候,可能就是替换几个class和前端页面,所以没有必要每次拷贝几百M的可执行代码
  2. 可以更容易调整tomcat的配置,把tomcat的配置从代码中脱离出来。

保持JSP的理由:

  1. 暂时不想花费大量时间更新前端页面,前端代码量比较大
  2. jsp没有什么大毛病,虽然spring并不是很推荐它。但spring最新版本,以及tomcat最新版本依然支持着。
  3. jsp技术,某种意义上,还是比较节约成本的。

本文涉及到几个知识点:

  • servlet
  • 动态web项目

二、搭建环境

工具和环境:

  • 操作系统:windows 11 家庭版
  • ide:使用sts即可。本人使用的是Version: 4.14.1.RELEASE版本。
  • 容器:tomcat使用最新的10.0.22
  • jdk-17
  • jquery-3.6.0

本文的例子就是为了升级做准备的,看是否可以比较容易地实现。

大体步骤如下:

  1. 使用sts,选择"spring starter project ",之后选择有关组件和选项。其中打包的选项选择"war",java选择17。注意,java8依然可以支持
  2. 修改pom.xml-支持jsp和war包
  3. 修改启动代码(不修改也可以)

2.1使用spring starter project创建工程

如果不想使用sts,仅仅是想看看有关配置,可以通过https://start.spring.io/在线生成示例。

以下几个图分别是目录结构图,项目配置信息图。

2.1.1目录结构图

修改后的启动代码(原来例子是两个类,现在合并为一个,不合并也可以):

package com.hc.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; @SpringBootApplication
public class SpringbootJspApplication extends SpringBootServletInitializer { @Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SpringbootJspApplication.class);
} public static void main(String[] args) {
SpringApplication.run(SpringbootJspApplication.class, args);
} }

这里最关键的是 SpringBootServletInitializer 。

2.1.2项目配置信息-部署

这里的关键是 src/main/webapp目录会映射到/,这个src/main/webapp就是用于存放前端代码的。当然,你要愿意修改为webContent,myhtml之类都可以,只要做好部署映射即可。

其它build path,java compiler略过。

2.1.3项目配置信息-project facets

注意:”dynamic web module"不要选择太老的,选择5.0即可。

这个"dynamic web mouule 5.0“意味着可以支持:

2.1.4项目配置信息-配置web上下文

首先打开"servers"视图,然后添加tomcat10,之后就可以设置上下文:

点击“edit”可以设置上下文。根据项目配置不同和sts的配置不同,有的时候,也可以在项目设置页面中直接设置上下文。

2.2修改pom.xml

这里是关键,以下是本例的pom.xml的内容:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.hc.demo</groupId>
<artifactId>springjsp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>springjsp</name>
<description>Demo project for Spring boot and jsp and war</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency> <!-- 以下1~4是为了支持jsp -->
<!-- 1添加servlet依赖模块 -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>10.0.22</version>
</dependency>
<!-- 2添加jstl标签库依赖模块 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!--3添加tomcat依赖模块.-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<!-- 4使用jsp引擎,springboot内置tomcat没有此依赖 -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>compile</scope>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- 配置war包插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warSourceExcludes>src/main/resources/**</warSourceExcludes>
<warName>springjsp</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
</pluginRepositories> </project>

主要是两个地方要修改:

  1. 配置jsp
  2. 配置war插件

以上两个修改,分类如以下两个地方:

2.2.1配置jsp

<!-- 以下1~4是为了支持jsp -->
<!-- 1添加servlet依赖模块 -->
<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat-servlet-api</artifactId>
    <version>10.0.22</version>
</dependency>
<!-- 2添加jstl标签库依赖模块 -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
</dependency>
<!--3添加tomcat依赖模块.-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<!-- 4使用jsp引擎,springboot内置tomcat没有此依赖 -->
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <scope>compile</scope>
</dependency>

此外,因为这里引入了"spring-boot-starter-tomcat",所以需要把它从“spring-boot-starter-web”移除掉,具体见完整pom.xml。

2.2.2配置war插件

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warSourceExcludes>src/main/resources/**</warSourceExcludes>
<warName>springjsp</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>

三、编写测试代码

3.1编写过滤器

具体过程略,一些列出过滤器代码:

package com.hc.demo.config.filter;

import java.io.IOException;

import org.springframework.web.filter.OncePerRequestFilter;

import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; public class MyFilter extends OncePerRequestFilter { @Override
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
HttpServletRequest request2 = (HttpServletRequest) request;
String orgin = request2.getHeader("origin");
HttpServletResponse res = (HttpServletResponse) response;
res.addHeader("Access-Control-Allow-Origin", orgin);
res.addHeader("Access-Control-Allow-Methods", "*");
res.addHeader("Access-Control-Allow-Headers", "content-type"); String url=request.getRequestURI().toString();
System.out.println(url);
FilterRequest req = new FilterRequest(request);
filterChain.doFilter(req, response);
}
}

注:

1.红色部分代码是为了便于观察过滤器是否生效。

2.在jdk17中,“servlet”的顶级包名以“jakarta"开头,这是一个很大的区别。

3.2编写一个接口

具体过程略,先列出控制器代码:

package com.hc.demo.student.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import com.hc.demo.student.service.StudentService; @Controller
@RequestMapping(value = "/student")
public class StudentController {
@Autowired
private StudentService studentService; @RequestMapping(value = "list")
@ResponseBody
public Object list() {
return studentService.queryAll();
}
}

3.3编写一个jsp页面

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jsp测试</title>
</head>
<style>
html, body {
width: 100%;
height: 100%;
} .jsp-example {
display: flex;
color: red;
font-size: 32px;
height: 20%;
margin-top: 10%;
margin-bottom:4px;
line-height: 50%;
text-align: center;
background-color: yellow;
flex-direction: column-reverse;
flex-wrap: wrap;
align-content: center;
justify-content: center;
}
#studentTable{
border-width: 4px;
border-style: solid;
border-color: lightgray;
width: 400px;
margin: 0 auto;
}
tr,td,th{
border-width: 1px;
border-style: solid;
border-color: lightgray;
text-align:center;
}
</style> <body>
<div class="jsp-example" id="dDivExample"></div>
<div id="dDivStudent">
<table id="studentTable">
<thead>
<tr>
<th>姓名</th>
<th>性别</th>
</tr>
</thead>
<tbody id="studentTableBody">
</tbody>
</table> </div>
</body>
<script src="/springjsp/plugin/jquery/jquery-3.6.0.min.js"></script>
<script>
$(function () {
document.getElementById("dDivExample").innerText="这是一个springboot3.0+jdk17+jsp+war的测试";
showStudent();
});
function showStudent(){
$.ajax({
url: '/springjsp/student/list',
type: 'POST',
dataType: 'json',
async: true,
success: function (rs, status, xhr) {
let htmlText="";
for(let i=0,len=rs.length;i<len;i++){
htmlText+="<tr><td>"+rs[i].NAME+"</td><td>"+rs[i].sex+"</td></tr>\n"
}
let _body=document.getElementById("studentTableBody");
_body.innerHTML=htmlText;
},
error: function (rs) {
alert("失败!");
}
});
}
</script> </html>

3.4配置wms

package com.hc.demo.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; import com.hc.demo.config.filter.MyFilter; @Configuration
public class MyWMS extends WebMvcConfigurationSupport { @Override
protected void addInterceptors(InterceptorRegistry registry) {
} @Override
public void addViewControllers(ViewControllerRegistry registry) {
// 为根增加默认的 映射,指向index.html
registry.addViewController("/").setViewName("index");
} @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations("classpath:/static/")
.addResourceLocations("classpath:/temploates/");
registry.addResourceHandler("/plugin/**").addResourceLocations("/plugin/");
super.addResourceHandlers(registry);
} /**
* 注册过滤器
* @return
*/
@Bean
public FilterRegistrationBean<MyFilter> registerAuthFilter() {
FilterRegistrationBean<MyFilter> registration = new FilterRegistrationBean<>();
MyFilter filter=new MyFilter();
registration.setFilter(filter);
registration.addUrlPatterns("/*");
registration.setName("authFilter");
registration.setOrder(1); //值越小,Filter越靠前。
return registration;
}
}

上文红色部分是需要关注的地方,分别设置根url,静态资源和过滤器。

注意:这是springboot3.0+spring6.0和以往的一个大区别:以前的版本过滤器设置需要新建一个web.xml,并在web.xml中配置过滤器。但是现在不需要了,这个无疑非常方便,非常合理。

当然这主要是因为 5.0的web moudule可以避免配置web.xml(这个有点烦人)。

四、打包

新建debug Configurations,如下图:

”jre“部分,”VM arguments"设置参数"-Dmaven.test.skip=true",避免无谓的测试。

其它设置大概如下:

  • goals- clean compile package,这是清理、编译,最后打包
  • jdk-17
  • 字符集-utf-8
  • jrebel 关闭

之后,点击“debug”,则运行如下:

[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< com.hc.demo:springjsp >------------------------
[INFO] Building springjsp 0.0.1-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/apache/maven/plugins/maven-clean-plugin/3.2.0/maven-clean-plugin-3.2.0.pom
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/3.2.0/maven-clean-plugin-3.2.0.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/3.2.0/maven-clean-plugin-3.2.0.pom (5.3 kB at 1.5 kB/s)
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/apache/maven/plugins/maven-plugins/35/maven-plugins-35.pom
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/35/maven-plugins-35.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/35/maven-plugins-35.pom (9.9 kB at 1.8 kB/s)
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/apache/maven/maven-parent/35/maven-parent-35.pom
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/35/maven-parent-35.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/35/maven-parent-35.pom (45 kB at 4.2 kB/s)
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/apache/apache/25/apache-25.pom
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/apache/25/apache-25.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/apache/25/apache-25.pom (21 kB at 5.5 kB/s)
[INFO]
[INFO] --- maven-clean-plugin:3.2.0:clean (default-clean) @ springjsp ---
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar (169 kB at 7.0 kB/s)
[INFO] Deleting E:\codes-java\git\learning\gitee\springjsp\target
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ springjsp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ springjsp ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 7 source files to E:\codes-java\git\learning\gitee\springjsp\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ springjsp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ springjsp ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 7 source files to E:\codes-java\git\learning\gitee\springjsp\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ springjsp ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) @ springjsp ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ springjsp ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-war-plugin:3.3.2:war (default-war) @ springjsp ---
[INFO] Packaging webapp
[INFO] Assembling webapp [springjsp] in [E:\codes-java\git\learning\gitee\springjsp\target\springjsp-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [E:\codes-java\git\learning\gitee\springjsp\src\main\webapp]
[INFO] Building war: E:\codes-java\git\learning\gitee\springjsp\target\springjsp.war
[INFO]
[INFO] --- spring-boot-maven-plugin:3.0.0-SNAPSHOT:repackage (repackage) @ springjsp ---
[INFO] Downloading from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-buildpack-platform/3.0.0-SNAPSHOT/maven-metadata.xml
[INFO] Downloaded from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-buildpack-platform/3.0.0-SNAPSHOT/maven-metadata.xml (2.4 kB at 1.5 kB/s)
[INFO] Downloading from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-buildpack-platform/3.0.0-SNAPSHOT/spring-boot-buildpack-platform-3.0.0-20220626.095848-608.pom
[INFO] Downloaded from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-buildpack-platform/3.0.0-SNAPSHOT/spring-boot-buildpack-platform-3.0.0-20220626.095848-608.pom (3.4 kB at 2.5 kB/s)
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/net/java/dev/jna/jna-platform/5.7.0/jna-platform-5.7.0.pom
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/net/java/dev/jna/jna-platform/5.7.0/jna-platform-5.7.0.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/net/java/dev/jna/jna-platform/5.7.0/jna-platform-5.7.0.pom (0 B at 0 B/s)
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/net/java/dev/jna/jna/5.7.0/jna-5.7.0.pom
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/net/java/dev/jna/jna/5.7.0/jna-5.7.0.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/net/java/dev/jna/jna/5.7.0/jna-5.7.0.pom (0 B at 0 B/s)
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/tomlj/tomlj/1.0.0/tomlj-1.0.0.pom
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/tomlj/tomlj/1.0.0/tomlj-1.0.0.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/tomlj/tomlj/1.0.0/tomlj-1.0.0.pom (0 B at 0 B/s)
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/antlr/antlr4-runtime/4.7.2/antlr4-runtime-4.7.2.pom
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/antlr/antlr4-runtime/4.7.2/antlr4-runtime-4.7.2.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/antlr/antlr4-runtime/4.7.2/antlr4-runtime-4.7.2.pom (0 B at 0 B/s)
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/antlr/antlr4-master/4.7.2/antlr4-master-4.7.2.pom
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/antlr/antlr4-master/4.7.2/antlr4-master-4.7.2.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/antlr/antlr4-master/4.7.2/antlr4-master-4.7.2.pom (0 B at 0 B/s)
[INFO] Downloading from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-loader-tools/3.0.0-SNAPSHOT/maven-metadata.xml
[INFO] Downloaded from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-loader-tools/3.0.0-SNAPSHOT/maven-metadata.xml (2.4 kB at 1.4 kB/s)
[INFO] Downloading from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-loader-tools/3.0.0-SNAPSHOT/spring-boot-loader-tools-3.0.0-20220626.095848-608.pom
[INFO] Downloaded from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-loader-tools/3.0.0-SNAPSHOT/spring-boot-loader-tools-3.0.0-20220626.095848-608.pom (2.3 kB at 1.4 kB/s)
[INFO] Downloading from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-buildpack-platform/3.0.0-SNAPSHOT/spring-boot-buildpack-platform-3.0.0-20220626.095848-608.jar
[INFO] Downloading from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-loader-tools/3.0.0-SNAPSHOT/spring-boot-loader-tools-3.0.0-20220626.095848-608.jar
[INFO] Downloaded from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-loader-tools/3.0.0-SNAPSHOT/spring-boot-loader-tools-3.0.0-20220626.095848-608.jar (247 kB at 39 kB/s)
[INFO] Downloaded from spring-snapshots: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-buildpack-platform/3.0.0-SNAPSHOT/spring-boot-buildpack-platform-3.0.0-20220626.095848-608.jar (240 kB at 35 kB/s)
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/net/java/dev/jna/jna-platform/5.7.0/jna-platform-5.7.0.jar
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/net/java/dev/jna/jna/5.7.0/jna-5.7.0.jar
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/tomlj/tomlj/1.0.0/tomlj-1.0.0.jar
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/antlr/antlr4-runtime/4.7.2/antlr4-runtime-4.7.2.jar
[INFO] Downloading from spring-milestones: https://repo.spring.io/milestone/org/codehaus/plexus/plexus-utils/1.5.8/plexus-utils-1.5.8.jar
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/net/java/dev/jna/jna-platform/5.7.0/jna-platform-5.7.0.jar
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/net/java/dev/jna/jna/5.7.0/jna-5.7.0.jar
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/tomlj/tomlj/1.0.0/tomlj-1.0.0.jar
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/antlr/antlr4-runtime/4.7.2/antlr4-runtime-4.7.2.jar
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.5.8/plexus-utils-1.5.8.jar
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/tomlj/tomlj/1.0.0/tomlj-1.0.0.jar (0 B at 0 B/s)
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/net/java/dev/jna/jna/5.7.0/jna-5.7.0.jar (0 B at 0 B/s)
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/net/java/dev/jna/jna-platform/5.7.0/jna-platform-5.7.0.jar (0 B at 0 B/s)
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/antlr/antlr4-runtime/4.7.2/antlr4-runtime-4.7.2.jar (0 B at 0 B/s)
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.5.8/plexus-utils-1.5.8.jar (268 kB at 38 kB/s)
[INFO] Replacing main artifact with repackaged archive
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:31 min
[INFO] Finished at: 2022-07-04T22:06:59+08:00
[INFO] ------------------------------------------------------------------------

五、测试

5.1安装和配置tomcat10

安装过程略。

主要是设置JAVA_HOME和日志编码。

5.1.1设置JAVA_HOME

打开TOMCAT10的bin\catalina.bat,在”setlocal"下插入一句:

set JAVA_HOME=D:\soft\develop-tool\java\jdk-17.0.3.1

5.1.2设置日志编码

打开tomcat10\conf\logging.properties,把所有的“UTF-8”修改为“GBK"即可。

5.2部署war包

把前面打包的E:\codes-java\git\learning\gitee\springjsp\target\springjsp.war复制到tomcat10\webapps下。

5.3运行war包

在cmd下,运行tomcat10下的startup.bat,当然之前,需要先打开Mysql。

控制台输出如下:

看起来很正常,默认8080已经打开。

切换到浏览器,输入:http://localhost:8080/springjsp/

结果如下图:

运行 正常。

六、小结

整个过程很顺利,麻烦的地方仅仅是配置pom.xml和在wms中配置静态资源。

和以前版本比起来,的确方便了不少。例如不要配置web.xml(实际上web module>=3.1即可),这样可以节省servlet,filter之类的配置。

Springboot3.0+spring6.0+JDK17+配置jsp和打war包的更多相关文章

  1. IDEA 工具项目的配置及如何打war包

    1. Project Structure 1.1 首先点击File-ProjectStructure,进入项目配置: 2.Project Settings配置 2.1 Project  2.1.1 f ...

  2. 在linux下把jsp文件 打包war格式(centos7)

    在linux下把jsp文件 打成war包 chmod -R 777 /data/jdk8u242-b08/bincd /data/TongWeb61712/deployment/TestCase//d ...

  3. 配置数据库连接池,Tomcat6.0 连接池的配置

    Tomcat6.0 连接池的配置1.本人当前使用的Tomcat版本为:6.0.20,oracle为稳定的9i版本 2.下文为方便起见,依习惯以%Tomcat_Home%表示Tomcat安装的目录,本人 ...

  4. Tomcat7.0/8.0 详细安装配置图解,以及UTF-8编码配置

    Tomcat7.0/8.0 详细安装配置图解,以及UTF-8编码配置 2017年01月24日 10:01:48 阅读数:51265 标签: tomcattomcat安装tomcat配置tomcat编码 ...

  5. JDK1.6.0+Tomcat6.0的安装配置

    JDK1.6.0+Tomcat6.0的安装配置是如何进行的呢?我们按照下面几个步骤来: 1.安装JDK 这是进行JSP开发的重要一步,也是安装JSP引擎(Tomcat.Resin.Weblogic等) ...

  6. SpringBoot3.0 + SpringSecurity6.0+JWT

    JWT_SpringSecurity SpringBoot3.0 + SpringSecurity6.0+JWT Spring Security 是 Spring 家族中的一个安全管理框架. 一般We ...

  7. WCF学习之旅—WCF4.0中的简化配置功能(十五)

    六 WCF4.0中的简化配置功能 WCF4.0为了简化服务配置,提供了默认的终结点.绑定和服务行为.也就是说,在开发WCF服务程序的时候,即使我们不提供显示的 服务终结点,WCF框架也能为我们的服务提 ...

  8. Redis 3.0 Cluster集群配置

    Redis 3.0 Cluster集群配置 安装环境依赖 安装gcc:yum install gcc 安装zlib:yum install zib 安装ruby:yum install ruby 安装 ...

  9. elasticsearch5.0.0 安装插件及配置过程

    elasticsearch5.0.0 安装插件及配置过程 由于es5.0是里程碑式的更新,所以很多变化的地方,暂时我就插件安装遇到的问题记录一下. 插件安装命令 2.3版本的安装命令 安装Marvel ...

  10. Spring4.0编程式定时任务配置

    看过很多定时调度的配置,大多使用XML配置,觉得比较麻烦,也比较老套.这里介绍一种基于spring4.0注解编程式配置定时任务,简单清晰,使用方便.. 至于引入spring相关jar这里不多说,直接切 ...

随机推荐

  1. dotnet SemanticKernel 入门 开篇

    本文将开坑告诉大家什么是 SemanticKernel 以及如何使用框架 众所周知 GPT 是一个大语言模型,能够参与的输入和输出是文本内容.而想要让 GPT 完成各项功能,则需要对接现有的编程世界. ...

  2. WPF 将控件放入到 UserControl 里获取 HwndSource 为空的情况

    本文记录将 WPF 控件放入到 UserControl 里,如果此 UserControl 没有被设置 Visibility 为可见过,那么放在此 UserControl 内的控件将获取不到 Hwnd ...

  3. keil 中未编译的代码灰色显示

    一.转载文章 转载:KEIL,#ifdef宏定义下失效代码差异性显示 注意keil的版本,太低的版本不具备灰色显示,据我所知在KEIL uVersion V5.31版本以上均可以. 二.使能灰色显示 ...

  4. C++多态与虚拟:C++编译器对函数名的改编(Name Mangling)

    如果函数名称都相同(也就是被overloaded),编译器在面对你的函数唤起动作时,究竟是如何确定调用哪个函数实体呢?事实上,编译器把所有同名的overloaded functions视为不同的函数, ...

  5. [WC/CTS2024] 线段树 题解

    Link 纪念一下场切题. 题意:给定一棵(分点不一定为中点)的线段树,给定若干个询问区间,问有多少个线段树上结点的集合,知道了这些结点对应的区间和就可以知道任何一个询问区间的和. 从询问区间开始考虑 ...

  6. 《最新出炉》系列入门篇-Python+Playwright自动化测试-44-鼠标操作-上篇

    1.简介 前边文章中已经讲解过鼠标的拖拽操作,今天宏哥在这里对其的其他操作进行一个详细地介绍和讲解,然后对其中的一些比较常见的.重要的操作单独拿出来进行详细的介绍和讲解. 2.鼠标操作语法 鼠标操作介 ...

  7. linux diff求两个文件的差集

    awk 从文本中过滤出需要的ip queryId_20231109214653_ipBatchQueryResult.json {"id":0,"ip":&qu ...

  8. Golang 版本 支付宝支付SDK app支付接口2.0

    参考技术贴: https://blog.csdn.net/ming2316780/article/details/86505883 对接文档: https://opendocs.alipay.com/ ...

  9. Linux中的man page指令

    以Linux上的date命令为例,在控制台输入 man date,将会展示如下界面: [vbird@www ~]$ man date DATE(1) User Commands DATE(1) # 请 ...

  10. 大数据之Hadoop集群的HDFS压力测试

    测试HDFS写性能 原文:sw-code 1)写测试的原理 2)测试内容:向HDFS集群写10个128MB的文件(3个机器每个4核,2 * 4 = 8 < 10 < 3 * 4 =12) ...