SpringBoot学习---SpringBoot打War包上传到tomcat

一. pop.xml配置文件

  • 二. 排除内置tomcat

  • 三. 修改Springboot启动类

  • 四. Maven打包工具package

  • 五. Xftp上传到webapps目录下

  • 六. 访问测试

一. pop.xml配置文件

默认是打jar包,修改成war包

二. 排除内置tomcat

<!--排除内嵌tomcat-->        <dependency>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-tomcat</artifactId>        <scope>provided</scope>        </dependency>

三. 修改Springboot启动类

@SpringBootApplicationpublic class RedisSessionManagerApplication extends SpringBootServletInitializer {public static void main(String[] args) {SpringApplication.run(RedisSessionManagerApplication.class, args);    }    @Override    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {return   builder.sources(RedisSessionManagerApplication.class);    }}

四. Maven打包工具package

五. Xftp上传到webapps目录下

六. 访问测试

放一个Contrller层测试代码

package com.xizi.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.IOException;import java.util.ArrayList;import java.util.List;@Controller@RequestMapping("test")public class TestController {//使用redis 的session管理  注意:当session中数据发生变化时必须将session中变化的数据同步到redis中    @RequestMapping("test")    public void test(HttpServletRequest request, HttpServletResponse response) throws IOException {List<String> list = (List<String>) request.getSession().getAttribute("list");        if(list==null){list = new ArrayList<>();        }        list.add("xxxx");        request.getSession().setAttribute("list",list);//每次session变化都要同步session        response.getWriter().println("size: " list.size());        response.getWriter().println("sessionid: " request.getSession().getId());    }    @RequestMapping("logout")    public void logout(HttpServletRequest request){//退出登录        request.getSession().invalidate();//失效    }}

来源:https://www.icode9.com/content-4-801401.html

(0)

相关推荐