新增springboot3支持.

This commit is contained in:
nieqiurong 2023-09-13 16:23:30 +08:00
parent 23244d91c2
commit 942f2e8cb7
64 changed files with 393 additions and 8 deletions

View File

@ -7,15 +7,17 @@ allprojects {
ext {
configuration = [
javaVersion = JavaVersion.VERSION_1_8
javaVersion = JavaVersion.VERSION_17
]
libraries = [
mybatisVersion = '3.5.13',
mybatisSpringVersion = '2.1.1',
mybatisSpring3Version = '3.0.2',
mybatisSpringBootStarterVersion = '2.3.1',
springVersion = '5.3.15',
springBootVersion = '2.5.3',
springBoot3Version = '3.1.3',
springCloudVersion = '3.1.1',
jsqlparserVersion = '4.6',
junitVersion = '5.9.0',
@ -27,6 +29,7 @@ ext {
"jsqlparser" : "com.github.jsqlparser:jsqlparser:${jsqlparserVersion}",
"mybatis" : "org.mybatis:mybatis:${mybatisVersion}",
"mybatis-spring" : "org.mybatis:mybatis-spring:${mybatisSpringVersion}",
"mybatis-spring3" : "org.mybatis:mybatis-spring:${mybatisSpring3Version}",
"mybatis-thymeleaf" : "org.mybatis.scripting:mybatis-thymeleaf:1.0.3",
"mybatis-freemarker" : "org.mybatis.scripting:mybatis-freemarker:1.2.3",
"mybatis-velocity" : "org.mybatis.scripting:mybatis-velocity:2.1.2",
@ -90,6 +93,10 @@ subprojects {
sourceCompatibility = "${javaVersion}"
targetCompatibility = "${javaVersion}"
compileJava {
options.release = 8
}
repositories {
mavenLocal()
maven { url "https://maven.aliyun.com/repository/public" }

View File

@ -1,4 +1,4 @@
APP_VERSION=3.5.3.2
APP_VERSION=3.5.4
APP_GROUP=com.baomidou
signing.keyId=1FD337F9
signing.password=243194995

View File

@ -2,7 +2,7 @@ apply plugin: 'kotlin'
dependencies {
api project(":mybatis-plus-core")
api "${lib."mybatis-spring"}"
implementation "${lib."mybatis-spring"}"
implementation "${lib."kotlin-stdlib-jdk8"}"
implementation "${lib."kotlin-reflect"}"

View File

@ -5,6 +5,8 @@ import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.statement.Statement;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.JRE;
import org.springframework.util.SerializationUtils;
import static org.assertj.core.api.Assertions.assertThat;
@ -22,6 +24,7 @@ class JsqlParserSimpleSerialTest {
"WHERE (e.id = ? OR e.NAME = ?)";
@Test
@EnabledOnJre(JRE.JAVA_8)
void test() throws JSQLParserException {
System.out.println("循环次数: " + len);
noSerial();

View File

@ -61,7 +61,7 @@ class GeneratePomTest {
Assertions.assertFalse(core.isOptional());
Dependency mybatisSpring = dependenciesMap.get("mybatis-spring");
Assertions.assertEquals("compile", mybatisSpring.getScope());
Assertions.assertFalse(mybatisSpring.isOptional());
Assertions.assertTrue(mybatisSpring.isOptional());
Dependency kotlinStdlib = dependenciesMap.get("kotlin-stdlib-jdk8");
Assertions.assertEquals("compile", kotlinStdlib.getScope());
Assertions.assertTrue(kotlinStdlib.isOptional());

View File

@ -7,7 +7,7 @@ dependencies {
api "${lib.'jsqlparser'}"
// TODO mybatis-plus-boot-starter里面把,spring项目不需要这个.
api "${lib."mybatis-spring"}"
implementation "${lib."mybatis-spring"}"
testImplementation "${lib.'spring-web'}"
testImplementation "${lib.'javax.servlet-api'}"

View File

@ -20,7 +20,12 @@ include 'mybatis-plus-core'
include 'mybatis-plus-annotation'
include 'mybatis-plus-extension'
include 'mybatis-plus-generator'
include 'mybatis-plus-boot-starter'
include 'mybatis-plus-boot-starter-test'
include 'mybatis-plus-bom'
include 'spring-boot-starter'
include ':spring-boot-starter:mybatis-plus-boot-starter'
include ':spring-boot-starter:mybatis-plus-boot-starter-test'
include ':spring-boot-starter:mybatis-plus-spring-boot-autoconfigure'
include ':spring-boot-starter:mybatis-plus-spring-boot3-starter'
include ':spring-boot-starter:mybatis-plus-spring-boot3-starter-test'
include ':spring-boot-starter:mybatis-plus-spring-boot-test-autoconfigure'

View File

@ -0,0 +1 @@
tasks.matching { it.group == 'publishing' }.each { it.enabled = false }

View File

@ -1,7 +1,8 @@
// copy mybatis mybatis-spring-boot-starter-test
dependencies {
api project(":mybatis-plus-boot-starter")
api project(":spring-boot-starter:mybatis-plus-boot-starter")
api project(":spring-boot-starter:mybatis-plus-spring-boot-test-autoconfigure")
implementation platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
api "org.springframework.boot:spring-boot-autoconfigure"
api "org.springframework.boot:spring-boot-starter-test"

View File

@ -1,5 +1,7 @@
dependencies {
api project(":mybatis-plus")
api "${lib."mybatis-spring"}"
api project(":spring-boot-starter:mybatis-plus-spring-boot-autoconfigure")
implementation platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
annotationProcessor "org.springframework.boot:spring-boot-autoconfigure-processor:${springBootVersion}"
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor:${springBootVersion}"

View File

@ -0,0 +1,16 @@
dependencies {
implementation project(":mybatis-plus")
implementation "${lib."mybatis-spring"}"
implementation "org.springframework.boot:spring-boot-autoconfigure:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-jdbc:${springBootVersion}"
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor:${springBootVersion}"
annotationProcessor "org.springframework.boot:spring-boot-autoconfigure-processor:${springBootVersion}"
implementation "${lib['mybatis-thymeleaf']}"
implementation "${lib.'mybatis-velocity'}"
implementation "${lib.'mybatis-freemarker'}"
implementation "${lib.'spring-cloud-commons'}"
testImplementation "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
testImplementation "${lib.'mybatis-spring-boot-starter'}"
}
compileJava.dependsOn(processResources)

View File

@ -0,0 +1,8 @@
dependencies {
implementation "org.springframework:spring-tx:${springVersion}"
implementation project(":spring-boot-starter:mybatis-plus-boot-starter")
implementation "org.springframework.boot:spring-boot-autoconfigure:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-jdbc:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-autoconfigure:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
}

View File

@ -0,0 +1,18 @@
java {
// toolchain {
// languageVersion.set(JavaLanguageVersion.of(17))
// }
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
dependencies {
api project(":spring-boot-starter:mybatis-plus-spring-boot3-starter")
api project(":spring-boot-starter:mybatis-plus-spring-boot-test-autoconfigure")
implementation platform("org.springframework.boot:spring-boot-dependencies:${springBoot3Version}")
api "org.springframework.boot:spring-boot-autoconfigure"
api "org.springframework.boot:spring-boot-starter-test"
api "org.springframework:spring-tx"
testImplementation "${lib.h2}"
}

View File

@ -0,0 +1,25 @@
package com.baomidou.mybatisplus.test.autoconfigure;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author miemie
* @since 2020-05-27
*/
//@MybatisPlusTest(properties = "spring.datasource.schema=classpath:schema.sql")
@MybatisPlusTest
class MybatisPlusSampleTest {
@Autowired
private SampleMapper sampleMapper;
@Test
void testInsert() {
Sample sample = new Sample();
sampleMapper.insert(sample);
assertThat(sample.getId()).isNotNull();
}
}

View File

@ -0,0 +1,12 @@
package com.baomidou.mybatisplus.test.autoconfigure;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author miemie
* @since 2020-05-27
*/
@SpringBootApplication
public class MybatisPlusTestApplication {
}

View File

@ -0,0 +1,13 @@
package com.baomidou.mybatisplus.test.autoconfigure;
import lombok.Data;
/**
* @author miemie
* @since 2020-05-27
*/
@Data
public class Sample {
private Long id;
private String name;
}

View File

@ -0,0 +1,12 @@
package com.baomidou.mybatisplus.test.autoconfigure;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* @author miemie
* @since 2020-05-27
*/
@Mapper
public interface SampleMapper extends BaseMapper<Sample> {
}

View File

@ -0,0 +1,8 @@
spring:
datasource:
schema: classpath:schema.sql
logging:
level:
org.springframework.jdbc: debug
com.baomidou.mybatisplus.test.autoconfigure: debug

View File

@ -0,0 +1,6 @@
drop table if exists sample;
create table if not exists sample
(
id bigint,
name varchar
);

View File

@ -0,0 +1,30 @@
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
// toolchain {
// languageVersion.set(JavaLanguageVersion.of(17))
// }
}
dependencies {
api project(":mybatis-plus")
api "${lib."mybatis-spring3"}"
api project(":spring-boot-starter:mybatis-plus-spring-boot-autoconfigure")
implementation platform("org.springframework.boot:spring-boot-dependencies:${springBoot3Version}")
annotationProcessor "org.springframework.boot:spring-boot-autoconfigure-processor:${springBoot3Version}"
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor:${springBoot3Version}"
api "org.springframework.boot:spring-boot-autoconfigure"
api "org.springframework.boot:spring-boot-starter-jdbc"
implementation "org.springframework.boot:spring-boot-configuration-processor"
implementation "org.springframework.boot:spring-boot-autoconfigure-processor"
implementation "${lib['mybatis-thymeleaf']}"
implementation "${lib.'mybatis-velocity'}"
implementation "${lib.'mybatis-freemarker'}"
implementation "${lib.'spring-cloud-commons'}"
testImplementation "org.springframework.boot:spring-boot-starter-test"
testImplementation "${lib.'mybatis-spring-boot-starter'}"
testImplementation "${lib.h2}"
}
compileJava.dependsOn(processResources)

View File

@ -0,0 +1,27 @@
package com.baomidou.mybatisplus.autoconfigure;
import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author miemie
* @since 2022-11-29
*/
@SpringBootApplication
public class ApplicationTestStartSuccess {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(ApplicationTestStartSuccess.class, args);
SqlSessionFactory bean = context.getBean(SqlSessionFactory.class);
Configuration configuration = bean.getConfiguration();
GlobalConfig config = GlobalConfigUtils.getGlobalConfig(configuration);
assertThat(config.getIdentifierGenerator()).isNotNull();
}
}

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2011-2020, baomidou (jobob@qq.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.baomidou.mybatisplus.test;
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* 属性测试
*
* @author nieqiurong 2019/5/4.
*/
class MybatisPlusPropertiesTest {
@Test
void resolveMapperLocationsTest() {
MybatisPlusProperties mybatisPlusProperties = new MybatisPlusProperties();
//默认扫描 classpath*:/mapper/**/*.xml
Assertions.assertEquals(mybatisPlusProperties.getMapperLocations()[0], "classpath*:/mapper/**/*.xml");
Assertions.assertEquals(2, mybatisPlusProperties.resolveMapperLocations().length);
//扫描不存在的路径
mybatisPlusProperties.setMapperLocations(new String[]{"classpath:mybatis-plus/*.xml"});
Assertions.assertEquals(mybatisPlusProperties.resolveMapperLocations().length, 0);
}
}

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2011-2020, baomidou (jobob@qq.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.baomidou.mybatisplus.test.entity;
import lombok.Data;
/**
* @author nieqiurong 2019/5/4.
*/
@Data
public class Test {
private Long id;
private String name;
}

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2011-2020, baomidou (jobob@qq.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.baomidou.mybatisplus.test.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.test.entity.Test;
/**
* @author nieqiurong 2019/5/4.
*/
public interface TestMapper extends BaseMapper<Test> {
}

View File

@ -0,0 +1,80 @@
/*
* Copyright (c) 2011-2020, baomidou (jobob@qq.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.baomidou.mybatisplus.test.pom;
import jodd.io.FileUtil;
import jodd.jerry.Jerry;
import jodd.jerry.JerryParser;
import jodd.lagarto.dom.LagartoDOMBuilder;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
/**
* 检查pom依赖
*
* @author nieqiurong 2019/2/9.
*/
class GeneratePomTest {
@Data
@AllArgsConstructor
private static class Dependency {
private String artifactId;
private String scope;
private boolean optional;
}
@Test
void test() throws IOException {
try (InputStream inputStream = new FileInputStream("build/publications/mavenJava/pom-default.xml")) {
JerryParser jerryParser = Jerry.create(new LagartoDOMBuilder().enableXmlMode());
Jerry doc = jerryParser.parse(FileUtil.readUTFString(inputStream));
Jerry dependencies = doc.s("dependencies dependency");
Map<String, Dependency> dependenciesMap = new HashMap<>();
dependencies.forEach($this -> {
String artifactId = $this.s("artifactId").text();
dependenciesMap.put(artifactId, new Dependency(artifactId, $this.s("scope").text(), Boolean.parseBoolean($this.s("optional").text())));
});
Dependency mp = dependenciesMap.get("mybatis-plus");
Assertions.assertEquals("compile", mp.getScope());
Assertions.assertFalse(mp.isOptional());
Dependency autoconfigure = dependenciesMap.get("spring-boot-autoconfigure");
Assertions.assertEquals("compile", autoconfigure.getScope());
Assertions.assertFalse(autoconfigure.isOptional());
Dependency jdbc = dependenciesMap.get("spring-boot-starter-jdbc");
Assertions.assertEquals("compile", jdbc.getScope());
Assertions.assertFalse(jdbc.isOptional());
Dependency configurationProcessor = dependenciesMap.get("spring-boot-configuration-processor");
Assertions.assertEquals("compile", configurationProcessor.getScope());
Assertions.assertTrue(configurationProcessor.isOptional());
Dependency autoconfigureProcessor = dependenciesMap.get("spring-boot-autoconfigure-processor");
Assertions.assertEquals("compile", autoconfigureProcessor.getScope());
Assertions.assertTrue(autoconfigureProcessor.isOptional());
Dependency bom = dependenciesMap.get("spring-boot-dependencies");
Assertions.assertEquals("import", bom.getScope());
Assertions.assertFalse(bom.isOptional());
}
}
}

View File

@ -0,0 +1,5 @@
spring:
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:test;MODE=mysql;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
username: sa

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.baomidou.mybatisplus.test.mapper.TestMapper">
</mapper>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.baomidou.mybatisplus.test.mapper.TestMapper">
</mapper>