java8升级java21方法步骤(完整pom文件升级及代码修改)
目录
- Java8升级java21
- 1、pom文件升级
- parent pom
- web pom
- service pom
- model pom
- dto pom
- dao pom
- commons pom
- 2、pom主要兼容问题整理
- 3、 yaml.XML
- 4、 升级修改配置
- 5、 代码修改
- 总结
java8升级java21
1、pom文件升级
parent pom
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>1.0.0</modelVersion> <groupId>test</groupId> <artifactId>test</artifactId> <version>1.0.0</version> <packaging>pom</packaging> <name>test</name> <properties> <project.version>${project.version}</project.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>21</java.version> <spring.boot.version>3.3.1</spring.boot.version> <spring.security.version>6.3.1</spring.security.version> <spring.cloud.version>4.1.3</spring.cloud.version> <spring.cloud.dependencies.version>2023.0.3</spring.cloud.dependencies.version> <spring.cloud.oauth2.version>2.2.5.RELEASE</spring.cloud.oauth2.version> <alibaba.cloud.nacos.version>2023.0.1.2</alibaba.cloud.nacos.version> <alibaba.cloud.dependencies>2.2.9.RELEASE</alibaba.cloud.dependencies> <mysql.driver.version>8.0.33</mysql.driver.version> <spring.jdbc.version>6.1.10</spring.jdbc.version> <myBATis-plus-boot-starter.version>3.5.7</mybatis-plus-boot-starter.version> <mybatis-plus.version>3.5.7</mybatis-plus.version> <org.mybatis.version>3.0.3</org.mybatis.version> <servlet.version>6.0.0</servlet.version> <jakarta.validation.version>3.1.0</jakarta.validation.version> <hibernate.validator.version>8.0.1.Final</hibernate.validator.version> <org.slf4j.version>2.0.13</org.slf4j.version> <org.apache.commons.version>2.12.0</org.apache.commons.version> <jackson.datatype.version>2.17.2</jackson.datatype.version> <commons-lang3.version>3.7</commons-lang3.version> <commons-io.version>2.2</commons-io.version> <commons-codec.version>1.10</commons-codec.version> <commons-fileupload.version>1.3.3</commons-fileupload.version> <commons-beanutils.version>1.9.3</commons-beanutils.version> <commons-collections.version>3.2.2</commons-collections.version> <httpclient.version>4.5.3</httpclient.version> <spring-doc.version>1.8.0</spring-doc.version> <guava.version>18.0</guava.version> <lombok.version>1.18.32</lombok.version> <fastjson.version>2.0.51</fastjson.version> <bboss-elasticsearch.version>7.1.1</bboss-elasticsearch.version> <dockerfile-maven.version>1.4.10</dockerfile-maven.version> <xxl-job.version>2.4.0</xxl-job.version> <rocketmq.version>2.0.4</rocketmq.version> <micrometer.version>1.13.1</micrometer.version> <poi.version>3.17</poi.version> <mapstruct.version>1.2.0.Final</mapstruct.version> <druid.version>1.2.23</druid.version> <hutool.version>4.5.11</hutool.version> <checkstyle.config.location>check-style.xml</checkstyle.config.location> </properties> <modules> <module>commons</module> <module>web</module> <module>dao</module> <module>dto</module> <module>model</module> <module>service</module> </modules> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>${spring.boot.version}</version> <type>pom</type> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-Redis</artifactId> <version>${spring.boot.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> <version>${spring.boot.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.jdbc.version}</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-config</artifactId> <version>${spring.security.version}</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring.cloud.dependencies.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>${alibaba.cloud.dependencies}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <version>${alibaba.cloud.nacos.version}</version> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> <version>${alibaba.cloud.nacos.version}</version> </dependency> <dependency> <groupId>org.apache.rocketmq</groupId> <artifactId>rocketmq-spring-boot-starter</artifactId> <version>${rocketmq.version}</version> </dependency> <dependency> <grouwww.devze.compId>org.apache.rocketmq</groupId> <artifactId>rocketmq-spring-boot</artifactId> <version>${rocketmq.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${org.slf4j.version}</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-pool2</artifactId> <version>${org.apache.commons.version}</version> </dependency> <dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct</artifactId> <version>${mapstruct.version}</version> </dependency> <dependency> <groupId>jakarta.servlet</groupId> <artifactId>jakarta.servlet-api</artifactId> <version>${servlet.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>jakarta.validation</groupId> <artifactId>jakarta.validation-api</artifactId> <version>${jakarta.validation.version}</version> </dependency> <dependency> <groupId>org.hibernate.validator</groupId> <artifactId>hibernate-validator</artifactId> <version>${hibernate.validator.version}</version> </dependency> <!-- mybatis-plus begin --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>${mybatis-plus-boot-starter.version}</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus</artifactId> <version>${mybatis-plus.version}</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-core</artifactId> <version>${mybatis-plus.version}</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-annotation</artifactId> <version>${mybatis-plus.version}</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>${org.mybatis.version}</version> </dependency> <!-- mybatis-plus end --> <!-- druid begin --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>${druid.version}</version> </dependency> <!-- druid end --> <!-- jdbc driver --> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <version>${mysql.driver.version}</version> <scope>runtime</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> </dependency> <!-- GENERAL UTILS begin --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>${commons-lang3.version}</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>${commons-io.version}</version> </dependency> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>${commons-codec.version}</version> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>${commons-fileupload.version}</version> </dependency> <dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> <version>${commons-beanutils.version}</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>${httpclient.version}</version> </dependency> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>${commons-collections.version}</version> </dependency> <!-- GENERAL UTILS end --> <!-- google java lib begin --> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>${guava.version}</version> </dependency> <!-- google java lib end --> <!-- fastjson json begin --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${fastjson.version}</version> </dependency> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>${hutool.version}</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>${poi.version}</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>${poi.version}</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml-schemas</artifactId> <version>${poi.version}</version> </dependency> <dependency> <groupId>com.bbossgroups.plugins</groupId> <artifactId>bboss-elasticsearch-rest-jdbc</artifactId> <version>${bboss-elasticsearch.version}</version> <exclusions> <exclusion> <artifactId>slf4j-log4j12</artifactId> <groupId>org.slf4j</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.xuxueli</groupId> <artifactId>xxl-job-core</artifactId> <version>$php{xxl-job.version}</version> </dependency> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> <version>${micrometer.version}</version> </dependency> <!-- Swagger --> <!--接口文档 v3--> <dependency> <groupId>org.springdoc</groupId&g编程t; <artifactId>springdoc-openapi-webmvc-core</artifactId> <version>${spring-doc.version}</version> </dependency> <!-- 引入swagger页面 --> <dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-ui</artifactId> <version>${spring-doc.version}</version> </dependency> <dependency> <groupId>test</groupId> <artifactId>model</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>test</groupId> <artifactId>commons</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>test</groupId> <artifactId>dao</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>test</groupId> <artifactId>service</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>test</groupId> <artifactId>dto</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>test</groupId> <artifactId>web</artifactId> <version>${project.version}</version> </dependency> </dependencies> </dependencyManagement> <build> <pluginManagement> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring.boot.version}</version> </plugin> <plugin> <groupId>com.spotify</groupId> <artifactId>dockerfile-maven-plugin</artifactId> <version>${dockerfile-maven.version}</version> <executions> <execution> <id>default</id> <goals> <goal>build</goal> <goal>push</goal> </goals> </execution> </executions> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.2</version> <configuration> <source>${java.version}</source> <target>${java.version}</target> <annotationProcessorPaths> <path> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>${mapstruct.version}</version> </path> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> </path> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok-mapstruct-binding</artifactId> <version>0.2.0</version> </path> </annotationProcessorPaths> </configuration> </plugin> <plugin> <groupId>org.flywaydb</groupId> <artifactId>flyway-maven-plugin</artifactId> <version>6.0.6</version> <dependencies> <dependency> <groupId>org.mariadb.jdbc</groupId> <artifactId>mariadb-java-client</artifactId> <version>2.5.0</version> </dependency> </dependencies> </plugin> </plugins> </build> </project>
web pom
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>test</artifactId> <groupId>test</groupId> <version>1.0.0</version> </parent> <modelVersion>1.0.0</modelVersion> <artifactId>web</artifactId> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>${spring.boot.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> <version>${spring.boot.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifaMXKhFrctId>spring-boot-starter-actuator</artifactId> <version>${spring.boot.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <version>${spring.boot.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-loadbalancer</artifactId> <version>${spring.cloud.version}</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bootstrap</artifactId> <version>${spring.cloud.version}</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> <version>${spring.cloud.version}</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-oauth2</artifactId> <version>${spring.cloud.oauth2.version}</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> <version>${spring.security.version}</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.datatype</groupId> <artifactId>jackson-datatype-jsr310</artifactId> <version>${jackson.datatype.version}</version> </dependency> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> </dependency> <dependency> <groupId>com.xuxueli</groupId> <artifactId>xxl-job-core</artifactId> </dependency> <dependency> <groupId>test</groupId> <artifactId>dto</artifactId> </dependency> <dependency> <groupId>test</groupId> <artifactId>commons</artifactId> </dependency> <dependency> <groupId>test</groupId> <artifactId>service</artifactId> </dependency> </dependencies> <build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <!-- 是否替换资源中的属性 --> <filtering>false</filtering> </resource> <resource> <directory>src/main/resources</directory> </resource> </resources> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>com.spotify</groupId> <artifactId>dockerfile-maven-plugin</artifactId> javascript <version>1.4.10</version> <configuration> <repository> ${docker.repository.registry}/${docker.repository.namespace}/${project.artifactId} </repository> <tag>latest</tag> <useMavenSettingsForAuth>true</useMavenSettingsForAuth> <buildArgs> <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE> <JAR_NAME>${project.artifactId}</JAR_NAME> </buildArgs> </configuration> </plugin> </plugins> </build> </project>
service pom
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>test</artifactId> <groupId>test</groupId> <version>1.0.0</version> </parent> <modelVersion>1.0.0</modelVersion> <artifactId>service</artifactId> <dependencies> <dependency> <groupId>test</groupId> <artifactId>model</artifactId> </dependency> <dependency> <groupId>test</groupId> <artifactId>commons</artifactId> </dependency> <dependency> <groupId>test</groupId> <artifactId>dao</artifactId> </dependency> <dependency> <groupId>test</groupId> <artifactId>dto</artifactId> </dependency> </dependencies> </project>
model pom
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>test</artifactId> <groupId>test</groupId> <version>1.0.0</version> </parent> <modelVersion>1.0.0</modelVersion> <artifactId>model</artifactId> <dependencies> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-annotation</artifactId> </dependency> </dependencies> </project>
dto pom
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>test</artifactId> <groupId>test</groupId> <version>1.0.0</version> </parent> <modelVersion>1.0.0</modelVersion> <artifactId>dto</artifactId> <dependencies> <dependency> <groupId>test</groupId> <artifactId>model</artifactId> </dependency> <dependency> <groupId>test</groupId> <artifactId>commons</artifactId> </dependency> <dependency> <artifactId>jackson-datatype-jsr310</artifactId> <groupId>com.fasterxml.jackson.datatype</groupId> <version>${jackson.datatype.version}</version> </dependency> <dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct</artifactId> </dependency> </dependencies> </project>
dao pom
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>test</artifactId> <groupId>test</groupId> <version>1.0.0</version> </parent> <modelVersion>1.0.0</modelVersion> <artifactId>dao</artifactId> <dependencies> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus</artifactId> </dependency> <dependency> <groupId>test</groupId> <artifactId>model</artifactId> </dependency> <dependency> <groupId>test</groupId> <artifactId>dto</artifactId> </dependency> </dependencies> <build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <!-- 是否替换资源中的属性 --> <filtering>false</filtering> </resource> <resource> <directory>src/main/resources</directory> <!-- <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>true</filtering> --> </resource> </resources> </build> </project>
commons pom
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>test</artifactId> <groupId>test</groupId> <version>1.0.0</version> </parent> <modelVersion>1.0.0</modelVersion> <artifactId>commons</artifactId> <dependencies> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-generator</artifactId> <version>3.0.6</version> </dependency> </dependencies> </project>
2、pom主要兼容问题整理
1.lombok版本需要升级至 1.8.30 及以上
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.30</version> </dependency>
2.mapstruct与lombok兼容问题
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.2</version> <configuration> <source>21</source> <target>21</target> <annotationProcessorPaths> <path> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>1.2.0.Final</version> </path> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.32</version> </path> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok-mapstruct-binding</artifactId> <version>0.2.0</version> </path> </annotationProcessorPaths> </configuration> </plugin> </plugins> </build>
3.nacos依赖替换
原依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <version>0.2.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> <version>0.2.2.RELEASE</version> </dependency>
新依赖
<dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <version>2023.0.1.2</version> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> <version>2023.0.1.2</version> </dependency>
4.mybaties需新增
<dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>3.0.3</version> </dependency>
5.jdbc修改artifactId
<dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <version>8.0.33</version> <scope>runtime</scope> </dependency>
6.jackson
<dependency> <artifactId>jackson-datatype-jsr310</artifactId> <groupId>com.fasterxml.jackson.datatype</groupId> <version>2.17.2</version> </dependency>
7.oauth2与nacos冲突需排除自动装配
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-oauth2</artifactId> <version>2.2.5.RELEASE</version> <exclusions> <exclusion> <artifactId>spring-security-oauth2-autoconfigure</artifactId> <groupId>org.springframework.security.oauth.boot</groupId> </exclusion> </exclusions> </dependency>
3、 yaml.xml
redis层级多一层data
spring: data: redis: host: 9.218.74.102 port: 6379 database: 0 password: ${redisPassword} timeout: 800 lettuce: pool: max-active: 8 max-idle: 8 min-idle: 0 max-wait: -1
mysql数据库url&username&password层级提升
spring: datasource: type: com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.jdbc.Driver url: username: password:
4、 升级修改配置
XxlJobConfig
appName字段名称更新
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor(); //xxlJobSpringExecutor.setAppName(appName); xxlJobSpringExecutor.setAppname(appName);
DataSourceConfig
分页及乐观锁插件配置
@Configuration @EnableTransactionManagement @MapperScan("com.test.mapper") public class DataSourceConfig { /** * 分页及乐观锁 插件 * * @return the page and optimistic locker interceptor */ @Bean public MybatisPlusInterceptor mybatisPlusInterceptor(){ MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor(); mybatisPlusInterceptor.addInnerInterceptor( new PaginationInnerInterceptor(DbType.MYSQL)); mybatisPlusInterceptor.addInnerInterceptor( new OptimisticLockerInnerInterceptor()); return mybatisPlusInterceptor; } }
SecurityConfig
原配置ResourceServerConfigurerAdapter已过时
@EnableResourceServer @EnableOAuth2Client @EnableGlobalMethodSecurity(prePostEnabled = true) @Configuration @Slf4j public class SecurityConfig extends ResourceServerConfigurerAdapter { @Override public void configure(HttpSecurity http) throws Exception { // @formatter:off http.authorizeRequests() .antMatchers( "/url", "/url" ).permitAll() .anyRequest().authenticated(); // @formatter:on } }
新配置
@EnableWebSecurity @Configuration @Slf4j @EnableConfigurationProperties({ResourceServerProperties.class}) public class SecurityConfig { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { // @formatter:off http.authorizeHttpRequests((authz) -> authz .requestMatchers( "url", "url") .authenticated()).httpBasic(withDefaults()); return http.build(); // @formatter:on } }
5、 代码修改
javax替换为jakarta
import javax.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank; import javax.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty; import javax.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest; import javax.annotation.PostConstruct; import jakarta.annotation.PostConstruct; import javax.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse; import javax.validation.constraints.FutureOrPresent; import jakarta.validation.constraints.FutureOrPresent; import javax.validation.ConstraintViolation; import jakarta.validation.ConstraintViolation; import javax.validation.Validator; import jakarta.validation.Validator; import javax.servlet.ServletOutputStream; import jakarta.servlet.ServletOutputStream;
mybatiesplus 数据库实体注解内容替换
@TableId(value = "id", type = IdType.ID_WORKER) @TableId(value = "id", type = IdType.ASSIGN_ID) @TableField(value = "start_time", strategy = FieldStrategy.IGNORED) @TableField(value = "start_time", updateStrategy = FieldStrategy.IGNORED)
XXLJob
原代码
@JobHandler(value = "Job") @Component @Slf4j public class Job extends IJobHandler { @Override public ReturnT<String> execute(String param) throws Exception { ShardingUtil.ShardingVO shardingVo = ShardingUtil.getShardingVo(); int index = shardingVo.getIndex(); int total = shardingVo.getTotal(); XxlJobHelper.log("log", index); service.execute(param); return ReturnT.SUCCESS; } }
新代码
@Component @Slf4j public class Job extends IJobHandler { @Override @XxlJob("Job") public void execute() throws Exception { int index = XxlJobHelper.getShardIndex(); int total = XxlJobHelper.getShardTotal(); XxlJobHelper.log("log", index); String param = XxlJobHelper.getJobParam(); service.execute(param); } }
总结
到此这篇关于java8升级java21的文章就介绍到这了,更多相关java8升级java21内容请搜索编程客栈(www.devze.com)以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程客栈(www.devze.com)!
精彩评论