diff --git a/mybatis-flex-solon-plugin/src/main/java/com/mybatisflex/solon/integration/MybatisAdapterFactoryFlex.java b/mybatis-flex-solon-plugin/src/main/java/com/mybatisflex/solon/integration/MybatisAdapterFactoryFlex.java index 1c2376b9..d331e4e4 100644 --- a/mybatis-flex-solon-plugin/src/main/java/com/mybatisflex/solon/integration/MybatisAdapterFactoryFlex.java +++ b/mybatis-flex-solon-plugin/src/main/java/com/mybatisflex/solon/integration/MybatisAdapterFactoryFlex.java @@ -1,17 +1,34 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * 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 + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * 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.mybatisflex.solon.integration; -import org.noear.solon.core.BeanWrap; -import org.noear.solon.core.Props; import org.apache.ibatis.solon.MybatisAdapter; import org.apache.ibatis.solon.MybatisAdapterFactory; +import org.noear.solon.core.BeanWrap; +import org.noear.solon.core.Props; /** - * 适配器工厂 for mybatis-flex + * MyBatis-Flex 适配器工厂。 * * @author noear * @since 2.2 */ public class MybatisAdapterFactoryFlex implements MybatisAdapterFactory { + @Override public MybatisAdapter create(BeanWrap dsWrap) { return new MybatisAdapterFlex(dsWrap); @@ -21,4 +38,5 @@ public class MybatisAdapterFactoryFlex implements MybatisAdapterFactory { public MybatisAdapter create(BeanWrap dsWrap, Props dsProps) { return new MybatisAdapterFlex(dsWrap, dsProps); } + } diff --git a/mybatis-flex-solon-plugin/src/main/java/com/mybatisflex/solon/integration/MybatisAdapterFlex.java b/mybatis-flex-solon-plugin/src/main/java/com/mybatisflex/solon/integration/MybatisAdapterFlex.java index 625c1da6..bd2e16cb 100644 --- a/mybatis-flex-solon-plugin/src/main/java/com/mybatisflex/solon/integration/MybatisAdapterFlex.java +++ b/mybatis-flex-solon-plugin/src/main/java/com/mybatisflex/solon/integration/MybatisAdapterFlex.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * 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 + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * 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.mybatisflex.solon.integration; import com.mybatisflex.core.FlexGlobalConfig; @@ -17,15 +33,19 @@ import org.noear.solon.core.event.EventBus; import javax.sql.DataSource; /** - * 适配器 for mybatis-flex + * MyBatis-Flex 适配器。 * * @author noear * @since 2.2 */ public class MybatisAdapterFlex extends MybatisAdapterDefault { + FlexSqlSessionFactoryBuilder factoryBuilderPlus; + FlexGlobalConfig globalConfig; + RowMapperInvoker rowMapperInvoker; + protected MybatisAdapterFlex(BeanWrap dsWrap) { super(dsWrap); @@ -107,25 +127,23 @@ public class MybatisAdapterFlex extends MybatisAdapterDefault { return factory; } - RowMapperInvoker rowMapperInvoker; - @Override public void injectTo(VarHolder varH) { super.injectTo(varH); - //@Db("db1") FlexGlobalConfig globalConfig; + // @Db("db1") FlexGlobalConfig globalConfig if (FlexGlobalConfig.class.isAssignableFrom(varH.getType())) { varH.setValue(this.getGlobalConfig()); return; } - //@Db("db1") RowMapperInvoker rowMapper; + // @Db("db1") RowMapperInvoker rowMapper if (RowMapperInvoker.class.equals(varH.getType())) { if (rowMapperInvoker == null) { rowMapperInvoker = new RowMapperInvoker(getFactory()); } varH.setValue(rowMapperInvoker); - return; } } + } diff --git a/mybatis-flex-solon-plugin/src/main/java/com/mybatisflex/solon/integration/XPluginImpl.java b/mybatis-flex-solon-plugin/src/main/java/com/mybatisflex/solon/integration/XPluginImpl.java index 2d18826e..5e386fe3 100644 --- a/mybatis-flex-solon-plugin/src/main/java/com/mybatisflex/solon/integration/XPluginImpl.java +++ b/mybatis-flex-solon-plugin/src/main/java/com/mybatisflex/solon/integration/XPluginImpl.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * 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 + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * 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.mybatisflex.solon.integration; import org.apache.ibatis.solon.integration.MybatisAdapterManager; @@ -5,15 +21,16 @@ import org.noear.solon.core.AopContext; import org.noear.solon.core.Plugin; /** + * 配置 MyBatis-Flex 插件。 + * * @author noear * @since 2.2 */ public class XPluginImpl implements Plugin { + @Override - public void start(AopContext context) throws Throwable { - // + public void start(AopContext context) { // 此插件的 solon.plugin.priority 会大于 mybatis-solon-plugin 的值 - // MybatisAdapterManager.setAdapterFactory(new MybatisAdapterFactoryFlex()); } diff --git a/mybatis-flex-solon-plugin/src/main/java/com/mybatisflex/solon/integration/package-info.java b/mybatis-flex-solon-plugin/src/main/java/com/mybatisflex/solon/integration/package-info.java new file mode 100644 index 00000000..2ca188b6 --- /dev/null +++ b/mybatis-flex-solon-plugin/src/main/java/com/mybatisflex/solon/integration/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * 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 + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * 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. + */ + +/** + * MyBatis-Flex Solon 支持。 + */ +package com.mybatisflex.solon.integration; \ No newline at end of file diff --git a/mybatis-flex-solon-plugin/src/main/java/com/mybatisflex/solon/service/impl/ServiceImpl.java b/mybatis-flex-solon-plugin/src/main/java/com/mybatisflex/solon/service/impl/ServiceImpl.java index 0e91f0d6..80ef2adc 100644 --- a/mybatis-flex-solon-plugin/src/main/java/com/mybatisflex/solon/service/impl/ServiceImpl.java +++ b/mybatis-flex-solon-plugin/src/main/java/com/mybatisflex/solon/service/impl/ServiceImpl.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *
- * 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 - *
- * http://www.apache.org/licenses/LICENSE-2.0 - *
- * 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. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * 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 + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * 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.mybatisflex.solon.service.impl;
@@ -19,6 +19,12 @@ import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.service.IService;
import org.noear.solon.annotation.Inject;
+/**
+ * 默认 {@link IService} 实现类。
+ *
+ * @param
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+/**
+ * IService 实现。
+ */
+package com.mybatisflex.solon.service.impl;
\ No newline at end of file
diff --git a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/ConditionalOnMybatisFlexDatasource.java b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/ConditionalOnMybatisFlexDatasource.java
index 604fcb4a..125cdf29 100644
--- a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/ConditionalOnMybatisFlexDatasource.java
+++ b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/ConditionalOnMybatisFlexDatasource.java
@@ -30,7 +30,11 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Iterator;
-
+/**
+ * 判断是否有 MyBatis-Flex 的多数据源配置。
+ *
+ * 如果配置文件中有 MyBatis-Flex 的多数据源配置,就加载 MyBatis-Flex 多数据源自动配置类。
+ */
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Conditional(ConditionalOnMybatisFlexDatasource.OnMybatisFlexDataSourceCondition.class)
diff --git a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/ConfigurationCustomizer.java b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/ConfigurationCustomizer.java
index c028c1d0..4a78c674 100644
--- a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/ConfigurationCustomizer.java
+++ b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/ConfigurationCustomizer.java
@@ -1,28 +1,33 @@
-/**
- * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
- *
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.mybatisflex.spring.boot;
import com.mybatisflex.core.mybatis.FlexConfiguration;
/**
- * 为 FlexConfiguration 做自定义的配置支持 {@link FlexConfiguration}
+ * 为 {@link FlexConfiguration} 做自定义的配置支持。
*/
@FunctionalInterface
public interface ConfigurationCustomizer {
- void customize(FlexConfiguration configuration);
+ /**
+ * 自定义配置 {@link FlexConfiguration}。
+ *
+ * @param configuration MyBatis Flex Configuration
+ */
+ void customize(FlexConfiguration configuration);
}
diff --git a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/FlexTransactionAutoConfiguration.java b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/FlexTransactionAutoConfiguration.java
index 22a983cb..fe73bf39 100644
--- a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/FlexTransactionAutoConfiguration.java
+++ b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/FlexTransactionAutoConfiguration.java
@@ -1,17 +1,17 @@
-/**
- * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
- *
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.mybatisflex.spring.boot;
@@ -26,16 +26,27 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.TransactionManagementConfigurer;
+/**
+ * MyBatis-Flex 事务自动配置。
+ */
@ConditionalOnClass(Db.class)
@Configuration(proxyBeanMethods = false)
@AutoConfigureAfter({MybatisFlexAutoConfiguration.class})
@AutoConfigureBefore({TransactionAutoConfiguration.class})
public class FlexTransactionAutoConfiguration implements TransactionManagementConfigurer {
+ /**
+ * 这里使用 final 修饰属性是因为:
+ * 1、调用 {@link #annotationDrivenTransactionManager} 方法会返回 TransactionManager 对象
+ * 需要保证两个对象的一致性。
+ */
private final FlexTransactionManager flexTransactionManager = new FlexTransactionManager();
- @Override
@Bean
+ @Override
public PlatformTransactionManager annotationDrivenTransactionManager() {
return flexTransactionManager;
}
diff --git a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MultiDataSourceAutoConfiguration.java b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MultiDataSourceAutoConfiguration.java
index 51ca2625..1ff89fba 100644
--- a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MultiDataSourceAutoConfiguration.java
+++ b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MultiDataSourceAutoConfiguration.java
@@ -34,7 +34,7 @@ import java.util.Map;
/**
- * 多数据源的配置支持
+ * MyBatis-Flex 多数据源的配置支持。
*/
@ConditionalOnMybatisFlexDatasource()
@Configuration(proxyBeanMethods = false)
@@ -50,7 +50,6 @@ public class MultiDataSourceAutoConfiguration {
dataSourceProperties = properties.getDatasource();
}
-
@Bean
@ConditionalOnMissingBean
public DataSource dataSource() {
@@ -71,6 +70,9 @@ public class MultiDataSourceAutoConfiguration {
return flexDataSource;
}
+ /**
+ * {@link com.mybatisflex.annotation.UseDataSource} 注解切换数据源切面。
+ */
@Bean
@ConditionalOnMissingBean
public DataSourceAdvice dataSourceAdvice() {
diff --git a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisLanguageDriverAutoConfiguration.java b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisLanguageDriverAutoConfiguration.java
index 72f17369..4453c82e 100644
--- a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisLanguageDriverAutoConfiguration.java
+++ b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/MybatisLanguageDriverAutoConfiguration.java
@@ -1,17 +1,17 @@
-/**
- * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
- *
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.mybatisflex.spring.boot;
@@ -30,117 +30,117 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
- * 脚本语言驱动的自动配置,平常一般项目用不到,只为了同步 mybatis 自带的 MybatisLanguageDriverAutoConfiguration
+ * 脚本语言驱动的自动配置,平常一般项目用不到,只为了同步 MyBatis 自带的 MybatisLanguageDriverAutoConfiguration。
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(LanguageDriver.class)
public class MybatisLanguageDriverAutoConfiguration {
- private static final String CONFIGURATION_PROPERTY_PREFIX = "mybatis-flex.scripting-language-driver";
+ private static final String CONFIGURATION_PROPERTY_PREFIX = "mybatis-flex.scripting-language-driver";
- /**
- * Configuration class for mybatis-freemarker 1.1.x or under.
- */
- @Configuration(proxyBeanMethods = false)
- @ConditionalOnClass(FreeMarkerLanguageDriver.class)
- @ConditionalOnMissingClass("org.mybatis.scripting.freemarker.FreeMarkerLanguageDriverConfig")
- public static class LegacyFreeMarkerConfiguration {
- @Bean
- @ConditionalOnMissingBean
- FreeMarkerLanguageDriver freeMarkerLanguageDriver() {
- return new FreeMarkerLanguageDriver();
- }
- }
-
- /**
- * Configuration class for mybatis-freemarker 1.2.x or above.
- */
- @Configuration(proxyBeanMethods = false)
- @ConditionalOnClass({ FreeMarkerLanguageDriver.class, FreeMarkerLanguageDriverConfig.class })
- public static class FreeMarkerConfiguration {
- @Bean
- @ConditionalOnMissingBean
- FreeMarkerLanguageDriver freeMarkerLanguageDriver(FreeMarkerLanguageDriverConfig config) {
- return new FreeMarkerLanguageDriver(config);
+ /**
+ * Configuration class for mybatis-freemarker 1.1.x or under.
+ */
+ @Configuration(proxyBeanMethods = false)
+ @ConditionalOnClass(FreeMarkerLanguageDriver.class)
+ @ConditionalOnMissingClass("org.mybatis.scripting.freemarker.FreeMarkerLanguageDriverConfig")
+ public static class LegacyFreeMarkerConfiguration {
+ @Bean
+ @ConditionalOnMissingBean
+ FreeMarkerLanguageDriver freeMarkerLanguageDriver() {
+ return new FreeMarkerLanguageDriver();
+ }
}
- @Bean
- @ConditionalOnMissingBean
- @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".freemarker")
- public FreeMarkerLanguageDriverConfig freeMarkerLanguageDriverConfig() {
- return FreeMarkerLanguageDriverConfig.newInstance();
- }
- }
+ /**
+ * Configuration class for mybatis-freemarker 1.2.x or above.
+ */
+ @Configuration(proxyBeanMethods = false)
+ @ConditionalOnClass({FreeMarkerLanguageDriver.class, FreeMarkerLanguageDriverConfig.class})
+ public static class FreeMarkerConfiguration {
+ @Bean
+ @ConditionalOnMissingBean
+ FreeMarkerLanguageDriver freeMarkerLanguageDriver(FreeMarkerLanguageDriverConfig config) {
+ return new FreeMarkerLanguageDriver(config);
+ }
- /**
- * Configuration class for mybatis-velocity 2.0 or under.
- */
- @Configuration(proxyBeanMethods = false)
- @ConditionalOnClass(org.mybatis.scripting.velocity.Driver.class)
- @ConditionalOnMissingClass("org.mybatis.scripting.velocity.VelocityLanguageDriverConfig")
- @SuppressWarnings("deprecation")
- public static class LegacyVelocityConfiguration {
- @Bean
- @ConditionalOnMissingBean
- org.mybatis.scripting.velocity.Driver velocityLanguageDriver() {
- return new org.mybatis.scripting.velocity.Driver();
- }
- }
-
- /**
- * Configuration class for mybatis-velocity 2.1.x or above.
- */
- @Configuration(proxyBeanMethods = false)
- @ConditionalOnClass({ VelocityLanguageDriver.class, VelocityLanguageDriverConfig.class })
- public static class VelocityConfiguration {
- @Bean
- @ConditionalOnMissingBean
- VelocityLanguageDriver velocityLanguageDriver(VelocityLanguageDriverConfig config) {
- return new VelocityLanguageDriver(config);
+ @Bean
+ @ConditionalOnMissingBean
+ @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".freemarker")
+ public FreeMarkerLanguageDriverConfig freeMarkerLanguageDriverConfig() {
+ return FreeMarkerLanguageDriverConfig.newInstance();
+ }
}
- @Bean
- @ConditionalOnMissingBean
- @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".velocity")
- public VelocityLanguageDriverConfig velocityLanguageDriverConfig() {
- return VelocityLanguageDriverConfig.newInstance();
- }
- }
-
- @Configuration(proxyBeanMethods = false)
- @ConditionalOnClass(ThymeleafLanguageDriver.class)
- public static class ThymeleafConfiguration {
- @Bean
- @ConditionalOnMissingBean
- ThymeleafLanguageDriver thymeleafLanguageDriver(ThymeleafLanguageDriverConfig config) {
- return new ThymeleafLanguageDriver(config);
+ /**
+ * Configuration class for mybatis-velocity 2.0 or under.
+ */
+ @Configuration(proxyBeanMethods = false)
+ @ConditionalOnClass(org.mybatis.scripting.velocity.Driver.class)
+ @ConditionalOnMissingClass("org.mybatis.scripting.velocity.VelocityLanguageDriverConfig")
+ @SuppressWarnings("deprecation")
+ public static class LegacyVelocityConfiguration {
+ @Bean
+ @ConditionalOnMissingBean
+ org.mybatis.scripting.velocity.Driver velocityLanguageDriver() {
+ return new org.mybatis.scripting.velocity.Driver();
+ }
}
- @Bean
- @ConditionalOnMissingBean
- @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf")
- public ThymeleafLanguageDriverConfig thymeleafLanguageDriverConfig() {
- return ThymeleafLanguageDriverConfig.newInstance();
+ /**
+ * Configuration class for mybatis-velocity 2.1.x or above.
+ */
+ @Configuration(proxyBeanMethods = false)
+ @ConditionalOnClass({VelocityLanguageDriver.class, VelocityLanguageDriverConfig.class})
+ public static class VelocityConfiguration {
+ @Bean
+ @ConditionalOnMissingBean
+ VelocityLanguageDriver velocityLanguageDriver(VelocityLanguageDriverConfig config) {
+ return new VelocityLanguageDriver(config);
+ }
+
+ @Bean
+ @ConditionalOnMissingBean
+ @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".velocity")
+ public VelocityLanguageDriverConfig velocityLanguageDriverConfig() {
+ return VelocityLanguageDriverConfig.newInstance();
+ }
}
- // This class provides to avoid the https://github.com/spring-projects/spring-boot/issues/21626 as workaround.
- @SuppressWarnings("unused")
- private static class MetadataThymeleafLanguageDriverConfig extends ThymeleafLanguageDriverConfig {
+ @Configuration(proxyBeanMethods = false)
+ @ConditionalOnClass(ThymeleafLanguageDriver.class)
+ public static class ThymeleafConfiguration {
+ @Bean
+ @ConditionalOnMissingBean
+ ThymeleafLanguageDriver thymeleafLanguageDriver(ThymeleafLanguageDriverConfig config) {
+ return new ThymeleafLanguageDriver(config);
+ }
- @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf.dialect")
- @Override
- public DialectConfig getDialect() {
- return super.getDialect();
- }
+ @Bean
+ @ConditionalOnMissingBean
+ @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf")
+ public ThymeleafLanguageDriverConfig thymeleafLanguageDriverConfig() {
+ return ThymeleafLanguageDriverConfig.newInstance();
+ }
- @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf.template-file")
- @Override
- public TemplateFileConfig getTemplateFile() {
- return super.getTemplateFile();
- }
+ // This class provides to avoid the https://github.com/spring-projects/spring-boot/issues/21626 as workaround.
+ @SuppressWarnings("unused")
+ private static class MetadataThymeleafLanguageDriverConfig extends ThymeleafLanguageDriverConfig {
+
+ @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf.dialect")
+ @Override
+ public DialectConfig getDialect() {
+ return super.getDialect();
+ }
+
+ @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf.template-file")
+ @Override
+ public TemplateFileConfig getTemplateFile() {
+ return super.getTemplateFile();
+ }
+
+ }
}
- }
-
}
diff --git a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/SpringBootVFS.java b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/SpringBootVFS.java
index 067954bf..a6d81953 100644
--- a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/SpringBootVFS.java
+++ b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/SpringBootVFS.java
@@ -1,17 +1,17 @@
-/**
- * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
- *
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.mybatisflex.spring.boot;
@@ -31,59 +31,58 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
- * Mybatis 的 VFS 支持
+ * MyBatis 的 VFS 支持。
*/
public class SpringBootVFS extends VFS {
- private static Charset urlDecodingCharset;
- private final ResourcePatternResolver resourceResolver;
+ private static Charset urlDecodingCharset;
- static {
- setUrlDecodingCharset(Charset.defaultCharset());
- }
-
- public SpringBootVFS() {
- this.resourceResolver = new PathMatchingResourcePatternResolver(getClass().getClassLoader());
- }
-
- @Override
- public boolean isValid() {
- return true;
- }
-
- @Override
- protected List
- * Default is system default charset.
- *
+ * Default is system default charset.
+ *
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.mybatisflex.spring.boot;
import org.mybatis.spring.SqlSessionFactoryBean;
/**
- * 为 FlexSqlSessionFactoryBean 做自定义的配置支持
+ * 为 FlexSqlSessionFactoryBean 做自定义的配置支持。
+ *
* @see com.mybatisflex.spring.FlexSqlSessionFactoryBean
*/
@FunctionalInterface
public interface SqlSessionFactoryBeanCustomizer {
- void customize(SqlSessionFactoryBean factoryBean);
+ /**
+ * 自定义 {@link SqlSessionFactoryBean}。
+ *
+ * @param factoryBean FlexSqlSessionFactoryBean
+ */
+ void customize(SqlSessionFactoryBean factoryBean);
}
diff --git a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/package-info.java b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/package-info.java
index b90c4ad2..b80209dc 100644
--- a/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/package-info.java
+++ b/mybatis-flex-spring-boot-starter/src/main/java/com/mybatisflex/spring/boot/package-info.java
@@ -1,16 +1,20 @@
-/**
- * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
- *
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.mybatisflex.spring.boot;
+
+/**
+ * MyBatis-Flex Spring Boot 支持。
+ */
+package com.mybatisflex.spring.boot;
\ No newline at end of file
diff --git a/mybatis-flex-spring/src/main/java/com/mybatisflex/spring/FlexSqlSessionFactoryBean.java b/mybatis-flex-spring/src/main/java/com/mybatisflex/spring/FlexSqlSessionFactoryBean.java
index 48e7697e..35bae23c 100644
--- a/mybatis-flex-spring/src/main/java/com/mybatisflex/spring/FlexSqlSessionFactoryBean.java
+++ b/mybatis-flex-spring/src/main/java/com/mybatisflex/spring/FlexSqlSessionFactoryBean.java
@@ -1,17 +1,17 @@
-/**
- * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
- *
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.mybatisflex.spring;
@@ -73,9 +73,11 @@ import static org.springframework.util.StringUtils.hasLength;
import static org.springframework.util.StringUtils.tokenizeToStringArray;
/**
- * spring 在定义 SqlSessionFactoryBean 的时候,需要替换为 FlexSqlSessionFactoryBean
- * 源于 {@link SqlSessionFactoryBean},主要是用于构建 {@link com.mybatisflex.core.mybatis.FlexConfiguration },而不是使用原生的 Configuration
- * 此代码主要是用于修改 {@link FlexSqlSessionFactoryBean#buildSqlSessionFactory()} 部分
+ * Spring 在定义 SqlSessionFactoryBean 的时候,需要替换为 FlexSqlSessionFactoryBean。
+ *
+ * 源于 {@link SqlSessionFactoryBean},主要是用于构建 {@link com.mybatisflex.core.mybatis.FlexConfiguration },而不是使用原生的 {@link Configuration}。
+ *
+ * 此代码主要是用于修改 {@link FlexSqlSessionFactoryBean#buildSqlSessionFactory()} 部分。
*/
public class FlexSqlSessionFactoryBean extends SqlSessionFactoryBean
implements FactoryBean
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.
+/*
+ * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.mybatisflex.spring;
@@ -23,6 +23,9 @@ import org.springframework.transaction.TransactionException;
import org.springframework.transaction.support.AbstractPlatformTransactionManager;
import org.springframework.transaction.support.DefaultTransactionStatus;
+/**
+ * MyBatis-Flex 事务支持。
+ */
public class FlexTransactionManager extends AbstractPlatformTransactionManager {
@Override
diff --git a/mybatis-flex-spring/src/main/java/com/mybatisflex/spring/datasource/DataSourceInterceptor.java b/mybatis-flex-spring/src/main/java/com/mybatisflex/spring/datasource/DataSourceInterceptor.java
index ae4b7412..e0cc7894 100644
--- a/mybatis-flex-spring/src/main/java/com/mybatisflex/spring/datasource/DataSourceInterceptor.java
+++ b/mybatis-flex-spring/src/main/java/com/mybatisflex/spring/datasource/DataSourceInterceptor.java
@@ -36,6 +36,11 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public class DataSourceInterceptor implements MethodInterceptor {
+ /**
+ * 缓存方法对应的数据源。
+ */
+ private final Map
+ *
+ * 2、{@code @Bean} 注入又会返回 TransactionManager 对象
+ *