Upgrade to struts7 & springboot3

master
Yan 3 weeks ago
parent 1d32bb6db2
commit 71943ec986

@ -1,48 +1,49 @@
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>struts2-spring-boot-integration</artifactId>
<artifactId>struts7-springboot3-integration</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>Spring Boot Struts Demo</name>
<name>Struts7 Spring-Boot3 HelloWorld Demo</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
<spring-boot.version>1.5.22.RELEASE</spring-boot.version>
<struts.version>2.5.30</struts.version>
<java.version>17</java.version>
<spring-boot.version>3.4.3</spring-boot.version>
<struts.version>7.0.3</struts.version>
<maven-compiler-plugin.version>3.14.0</maven-compiler-plugin.version>
<servlet-api.version>6.1.0</servlet-api.version>
<jsp-api.version>4.0.0</jsp-api.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<groupId>jakarta.servlet.jsp</groupId>
<artifactId>jakarta.servlet.jsp-api</artifactId>
<version>${jsp-api.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>8.5.78</version>
<groupId>jakarta.servlet.jsp.jstl</groupId>
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
@ -55,15 +56,19 @@
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-java8-support-plugin</artifactId>
<version>2.5.2</version>
<artifactId>struts2-convention-plugin</artifactId>
<version>${struts.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>

@ -1,13 +1,39 @@
package com.example.demo;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class Application {
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public FilterRegistrationBean<StrutsPrepareAndExecuteFilter> filterRegistrationBean() {
Collection<String> urlPatterns = new ArrayList<>();
urlPatterns.add("/*");
FilterRegistrationBean<StrutsPrepareAndExecuteFilter> registrationBean = new FilterRegistrationBean<>();
StrutsPrepareAndExecuteFilter struts = new StrutsPrepareAndExecuteFilter();
registrationBean.setFilter(struts);
registrationBean.setName("strutsFilter");
registrationBean.setOrder(1);
registrationBean.setUrlPatterns(urlPatterns);
return registrationBean;
}
}

@ -1,19 +1,13 @@
package com.example.demo.action;
import com.example.demo.service.UserService;
import com.opensymphony.xwork2.ActionSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.apache.struts2.ActionSupport;
@SuppressWarnings("serial")
public class HelloAction extends ActionSupport {
@Autowired
protected UserService userService;
@Override
public String execute() throws Exception {
return SUCCESS;
}
@Override
public String execute() throws Exception {
return SUCCESS;
}
}

@ -1,19 +0,0 @@
package com.example.demo.config;
import org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class Struts2Configuration {
@Bean
public FilterRegistrationBean someFilterRegistration() {
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(new StrutsPrepareAndExecuteFilter());
registration.addUrlPatterns("*");
return registration;
}
}

@ -1,9 +0,0 @@
package com.example.demo.service;
/**
* user service
*
* @author linux_china
*/
public interface UserService {
}

@ -1,14 +0,0 @@
package com.example.demo.service.impl;
import org.springframework.stereotype.Service;
import com.example.demo.service.UserService;
/**
* user service implementation
*
* @author linux_china
*/
@Service
public class UserServiceImpl implements UserService {
}

@ -1 +1,2 @@
spring.application.name=struts2-boot-demo
spring.application.name=struts7-springboot3-integration
server.contextPath=/webapp

@ -2,9 +2,7 @@
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.objectFactory" value="spring" />
<package name="default" extends="struts-default" namespace='/'>
<action name="hello"

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring Struts 2</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

@ -7,8 +7,9 @@
<title>Hello World</title>
</head>
<body>
<h2>
Hello World!!!
</h2>
<h2>
Hello World!!!
</h2>
<a href="index">Index Page </a>
</body>
</html>

@ -9,5 +9,6 @@
</head>
<body>
<h2>Hello, Index Page!!!</h2>
<a href="hello">Hello Page</a>
</body>
</html>
Loading…
Cancel
Save