Skip to content

Commit 841c49b

Browse files
committed
update springboot 3.x
1 parent 5b06cac commit 841c49b

37 files changed

+184
-137
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ build/
3131

3232
### VS Code ###
3333
.vscode/
34-
*.mv.db
34+
*.db
3535
*.trace.db

pom.xml

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@
66
<parent>
77
<groupId>org.springframework.boot</groupId>
88
<artifactId>spring-boot-starter-parent</artifactId>
9-
<version>2.7.8</version>
9+
<version>3.0.6</version>
1010
<relativePath/> <!-- lookup parent from repository -->
1111
</parent>
1212

1313
<groupId>com.codingapi.springboot</groupId>
1414
<artifactId>springboot-parent</artifactId>
15-
<version>1.5.18</version>
15+
<version>2.0.0</version>
1616

1717
<url>https://github.com/codingapi/springboot-framewrok</url>
1818
<name>springboot-parent</name>
1919
<description>springboot-parent project for Spring Boot</description>
2020

2121
<properties>
22-
<java.version>1.8</java.version>
22+
<java.version>17</java.version>
2323

2424
<!-- maven properties-->
2525
<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
26-
<maven.compile.source>1.8</maven.compile.source>
27-
<maven.compile.target>1.8</maven.compile.target>
26+
<maven.compile.source>17</maven.compile.source>
27+
<maven.compile.target>17</maven.compile.target>
2828
<maven.source.plugin>3.0.1</maven.source.plugin>
2929
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
3030
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>

springboot-starter-data-fast/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
<parent>
66
<artifactId>springboot-parent</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>1.5.18</version>
8+
<version>2.0.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

1212
<artifactId>springboot-starter-data-fast</artifactId>
1313

1414
<properties>
15-
<java.version>1.8</java.version>
15+
<java.version>17</java.version>
1616
</properties>
1717

1818

springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/DataFastConfiguration.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
1212
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
1313

14-
import javax.persistence.EntityManager;
14+
import jakarta.persistence.EntityManager;
1515
import java.util.List;
1616

1717
@Configuration

springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/executor/JpaExecutor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import lombok.AllArgsConstructor;
66
import org.springframework.data.domain.Page;
77

8-
import javax.persistence.EntityManager;
8+
import jakarta.persistence.EntityManager;
99
import java.util.Collection;
1010
import java.util.List;
1111

springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/executor/JpaQuery.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import org.springframework.util.ReflectionUtils;
88
import org.springframework.util.StringUtils;
99

10-
import javax.persistence.EntityManager;
11-
import javax.persistence.Parameter;
12-
import javax.persistence.Query;
10+
import jakarta.persistence.EntityManager;
11+
import jakarta.persistence.Parameter;
12+
import jakarta.persistence.Query;
1313
import java.lang.reflect.Field;
1414
import java.util.Set;
1515

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
com.codingapi.springboot.fast.DataFastConfiguration
2+
com.codingapi.springboot.fast.registrar.DataFastBeanDefinitionRegistrar

springboot-starter-data-fast/src/test/java/com/codingapi/springboot/fast/entity/Demo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import lombok.Getter;
44
import lombok.Setter;
55

6-
import javax.persistence.*;
6+
import jakarta.persistence.*;
77

88
@Setter
99
@Getter

springboot-starter-id-generator/pom.xml

+9-6
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,33 @@
55
<parent>
66
<artifactId>springboot-parent</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>1.5.18</version>
8+
<version>2.0.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

1212
<artifactId>springboot-starter-id-generator</artifactId>
1313

1414
<properties>
15-
<java.version>1.8</java.version>
15+
<java.version>17</java.version>
1616
</properties>
1717

1818
<dependencies>
1919

20-
2120
<dependency>
22-
<groupId>com.h2database</groupId>
23-
<artifactId>h2</artifactId>
21+
<groupId>org.xerial</groupId>
22+
<artifactId>sqlite-jdbc</artifactId>
2423
</dependency>
2524

26-
2725
<dependency>
2826
<groupId>commons-dbutils</groupId>
2927
<artifactId>commons-dbutils</artifactId>
3028
</dependency>
3129

30+
<dependency>
31+
<groupId>org.springframework</groupId>
32+
<artifactId>spring-jdbc</artifactId>
33+
</dependency>
34+
3235
</dependencies>
3336

3437
</project>

springboot-starter-id-generator/src/main/java/com/codingapi/springboot/generator/AutoConfiguration.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.codingapi.springboot.generator;
22

33
import com.codingapi.springboot.generator.dao.IdKeyDao;
4-
import com.codingapi.springboot.generator.properties.GeneratorProperties;
4+
import com.codingapi.springboot.generator.properties.GeneratorJdbcProperties;
55
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
66
import org.springframework.boot.context.properties.ConfigurationProperties;
77
import org.springframework.context.annotation.Bean;
@@ -11,15 +11,15 @@
1111
public class AutoConfiguration {
1212

1313
@Bean
14-
@ConfigurationProperties(prefix = "codingapi.id.generator")
15-
public GeneratorProperties generatorProperties() {
16-
return new GeneratorProperties();
14+
@ConfigurationProperties(prefix = "codingapi.id.jdbc.generator")
15+
public GeneratorJdbcProperties generatorJdbcProperties() {
16+
return new GeneratorJdbcProperties();
1717
}
1818

1919
@Bean(initMethod = "init")
2020
@ConditionalOnMissingBean
21-
public IdKeyDao idKeyDao(GeneratorProperties generatorProperties) {
22-
IdKeyDao keyDao = new IdKeyDao(generatorProperties.getJdbcUrl());
21+
public IdKeyDao idKeyDao(GeneratorJdbcProperties generatorJdbcProperties) {
22+
IdKeyDao keyDao = new IdKeyDao(generatorJdbcProperties.openDataSource());
2323
IdGeneratorContext.getInstance().init(keyDao);
2424
return keyDao;
2525
}

springboot-starter-id-generator/src/main/java/com/codingapi/springboot/generator/dao/DbHelper.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
package com.codingapi.springboot.generator.dao;
22

33
import org.apache.commons.dbutils.QueryRunner;
4-
import org.h2.jdbcx.JdbcDataSource;
54

5+
import javax.sql.DataSource;
66
import java.sql.Connection;
77
import java.sql.SQLException;
88

99
public class DbHelper<T> {
1010

11-
private final JdbcDataSource dataSource;
11+
private final DataSource dataSource;
1212
private final QueryRunner queryRunner;
1313

1414

15-
public DbHelper(String jdbcUrl) {
16-
this.dataSource = new JdbcDataSource();
15+
public DbHelper(DataSource dataSource) {
16+
this.dataSource = dataSource;
1717
this.queryRunner = new QueryRunner();
18-
this.dataSource.setURL(jdbcUrl);
1918
}
2019

2120
public void execute(IExecute execute) throws SQLException {

springboot-starter-id-generator/src/main/java/com/codingapi/springboot/generator/dao/IdKeyDao.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.apache.commons.dbutils.QueryRunner;
66
import org.apache.commons.dbutils.ResultSetHandler;
77

8+
import javax.sql.DataSource;
89
import java.sql.Connection;
910
import java.sql.SQLException;
1011
import java.util.ArrayList;
@@ -16,8 +17,8 @@ public class IdKeyDao {
1617

1718
private final ResultSetHandler<List<IdKey>> handler;
1819

19-
public IdKeyDao(String jdbcUrl) {
20-
this.dbHelper = new DbHelper<>(jdbcUrl);
20+
public IdKeyDao(DataSource dataSource) {
21+
this.dbHelper = new DbHelper<>(dataSource);
2122
this.handler = rs -> {
2223
List<IdKey> list = new ArrayList<>();
2324
while (rs.next()) {
@@ -32,8 +33,8 @@ public IdKeyDao(String jdbcUrl) {
3233
}
3334

3435
@SneakyThrows
35-
public boolean save(IdKey generator) {
36-
return dbHelper.update(new DbHelper.IUpdate() {
36+
public void save(IdKey generator) {
37+
dbHelper.update(new DbHelper.IUpdate() {
3738
@Override
3839
public int update(Connection connection, QueryRunner queryRunner) throws SQLException {
3940
List<IdKey> list = queryRunner.query(connection, "SELECT * FROM ID_GENERATOR WHERE TAG = ?", handler, generator.getKey());
@@ -44,7 +45,7 @@ public int update(Connection connection, QueryRunner queryRunner) throws SQLExce
4445
String sql = "INSERT INTO ID_GENERATOR (ID, UPDATE_TIME, TAG) VALUES (?, ?, ?)";
4546
return queryRunner.update(connection, sql, generator.getId(), generator.getUpdateTime(), generator.getKey());
4647
}
47-
}) > 0;
48+
});
4849
}
4950

5051

@@ -61,7 +62,7 @@ public List<IdKey> query(Connection connection, QueryRunner queryRunner) throws
6162

6263
@SneakyThrows
6364
public IdKey updateMaxId(IdKey generator) {
64-
return dbHelper.updateAndQuery(new DbHelper.IUpdateAndQuery<List<IdKey>>() {
65+
return dbHelper.updateAndQuery(new DbHelper.IUpdateAndQuery<>() {
6566
@Override
6667
public List<IdKey> updateAndQuery(Connection connection, QueryRunner queryRunner) throws SQLException {
6768
queryRunner.update(connection, "UPDATE ID_GENERATOR SET ID = ID + 1 WHERE TAG = ?", generator.getKey());
@@ -73,7 +74,7 @@ public List<IdKey> updateAndQuery(Connection connection, QueryRunner queryRunner
7374

7475
@SneakyThrows
7576
public List<IdKey> findAll() throws SQLException {
76-
return dbHelper.query(new DbHelper.IQuery<List<IdKey>>() {
77+
return dbHelper.query(new DbHelper.IQuery<>() {
7778
@Override
7879
public List<IdKey> query(Connection connection, QueryRunner queryRunner) throws SQLException {
7980
return queryRunner.query(connection, "SELECT * FROM ID_GENERATOR", handler);
@@ -85,8 +86,8 @@ private void init() throws SQLException {
8586
dbHelper.execute(new DbHelper.IExecute() {
8687
@Override
8788
public void execute(Connection connection, QueryRunner queryRunner) throws SQLException {
88-
String sql = "CREATE TABLE IF NOT EXISTS ID_GENERATOR (TAG VARCHAR(128) NOT NULL, ID BIGINT NOT NULL, UPDATE_TIME BIGINT NOT NULL, PRIMARY KEY (TAG))";
89-
queryRunner.execute(connection, sql);
89+
String sql = "CREATE TABLE IF NOT EXISTS ID_GENERATOR (TAG TEXT NOT NULL, ID INTEGER NOT NULL, UPDATE_TIME INTEGER NOT NULL, PRIMARY KEY (TAG))";
90+
queryRunner.update(connection, sql);
9091
}
9192
});
9293
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.codingapi.springboot.generator.properties;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
import org.springframework.jdbc.datasource.DriverManagerDataSource;
6+
7+
import javax.sql.DataSource;
8+
9+
@Setter
10+
@Getter
11+
public class GeneratorJdbcProperties {
12+
13+
private String jdbcUrl = "jdbc:sqlite:db.db";
14+
15+
private String jdbcDriver = "org.sqlite.JDBC";
16+
17+
private String jdbcUsername = "sa";
18+
19+
private String jdbcPassword = "sa";
20+
21+
public DataSource openDataSource() {
22+
final DriverManagerDataSource dataSource = new DriverManagerDataSource();
23+
dataSource.setDriverClassName(jdbcDriver);
24+
dataSource.setUrl(jdbcUrl);
25+
dataSource.setUsername(jdbcUsername);
26+
dataSource.setPassword(jdbcPassword);
27+
return dataSource;
28+
}
29+
}

springboot-starter-id-generator/src/main/java/com/codingapi/springboot/generator/properties/GeneratorProperties.java

-13
This file was deleted.

springboot-starter-security-jwt/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>1.5.18</version>
9+
<version>2.0.0</version>
1010
</parent>
1111

1212
<artifactId>springboot-starter-security-jwt</artifactId>
@@ -15,7 +15,7 @@
1515
<description>springboot-starter-security-jwt project for Spring Boot</description>
1616

1717
<properties>
18-
<java.version>1.8</java.version>
18+
<java.version>17</java.version>
1919
</properties>
2020

2121
<dependencies>

springboot-starter-security-jwt/src/main/java/com/codingapi/springboot/security/AutoConfiguration.java

+11-10
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import org.springframework.core.env.Environment;
1313
import org.springframework.security.authentication.AuthenticationProvider;
1414
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
15-
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
1615
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
16+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
1717
import org.springframework.security.core.userdetails.User;
1818
import org.springframework.security.core.userdetails.UserDetails;
1919
import org.springframework.security.core.userdetails.UserDetailsService;
@@ -25,7 +25,7 @@
2525
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
2626

2727
@Configuration
28-
@EnableMethodSecurity
28+
@EnableWebSecurity
2929
public class AutoConfiguration {
3030

3131
@Bean
@@ -64,21 +64,22 @@ public SecurityLoginHandler securityLoginHandler(){
6464

6565
@Bean
6666
@ConditionalOnMissingBean
67-
public SecurityFilterChain filterChain(HttpSecurity http, Jwt jwt,SecurityLoginHandler loginHandler,
67+
public SecurityFilterChain filterChain(HttpSecurity security, Jwt jwt,SecurityLoginHandler loginHandler,
6868
SecurityJwtProperties properties) throws Exception {
6969
//before add addCorsMappings to enable cors.
70-
http.cors();
70+
security.httpBasic().disable();
71+
security.cors();
7172
if(properties.isDisableCsrf() ){
72-
http.csrf().disable();
73+
security.csrf().disable();
7374
}
74-
http.apply(new HttpSecurityConfigurer(jwt,loginHandler,properties));
75-
http
75+
security.apply(new HttpSecurityConfigurer(jwt,loginHandler,properties));
76+
security
7677
.exceptionHandling()
7778
.authenticationEntryPoint(new MyUnAuthenticationEntryPoint())
7879
.accessDeniedHandler(new MyAccessDeniedHandler())
7980
.and()
80-
.authorizeRequests()
81-
.antMatchers(properties.getAuthenticatedUrls()).authenticated()
81+
.authorizeHttpRequests()
82+
.requestMatchers(properties.getAuthenticatedUrls()).authenticated()
8283
.and()
8384
//default login url :/login
8485
.formLogin()
@@ -92,7 +93,7 @@ public SecurityFilterChain filterChain(HttpSecurity http, Jwt jwt,SecurityLoginH
9293
.logoutSuccessHandler(new MyLogoutSuccessHandler())
9394
.permitAll();
9495

95-
return http.build();
96+
return security.build();
9697
}
9798

9899

springboot-starter-security-jwt/src/main/java/com/codingapi/springboot/security/configurer/WebSecurityConfigurer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class WebSecurityConfigurer implements WebSecurityCustomizer {
1515
@Override
1616
public void customize(WebSecurity web) {
1717
//ignoring security filters request url
18-
web.ignoring().antMatchers(securityJwtProperties.getIgnoreUrls());
18+
web.ignoring().requestMatchers(securityJwtProperties.getIgnoreUrls());
1919
}
2020

2121
}

0 commit comments

Comments
 (0)