1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.spring.boot.autoconfigure;
17
18 import org.apache.ibatis.scripting.LanguageDriver;
19 import org.mybatis.scripting.freemarker.FreeMarkerLanguageDriver;
20 import org.mybatis.scripting.freemarker.FreeMarkerLanguageDriverConfig;
21 import org.mybatis.scripting.thymeleaf.ThymeleafLanguageDriver;
22 import org.mybatis.scripting.thymeleaf.ThymeleafLanguageDriverConfig;
23 import org.mybatis.scripting.velocity.VelocityLanguageDriver;
24 import org.mybatis.scripting.velocity.VelocityLanguageDriverConfig;
25 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
26 import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
27 import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
28 import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
29 import org.springframework.boot.context.properties.ConfigurationProperties;
30 import org.springframework.context.annotation.Bean;
31 import org.springframework.context.annotation.Configuration;
32
33
34
35
36
37
38
39
40 @Configuration(proxyBeanMethods = false)
41 @ConditionalOnClass(LanguageDriver.class)
42 public class MybatisLanguageDriverAutoConfiguration {
43
44 private static final String CONFIGURATION_PROPERTY_PREFIX = "mybatis.scripting-language-driver";
45
46
47
48
49 @Configuration(proxyBeanMethods = false)
50 @ConditionalOnClass(FreeMarkerLanguageDriver.class)
51 @ConditionalOnMissingClass("org.mybatis.scripting.freemarker.FreeMarkerLanguageDriverConfig")
52 public static class LegacyFreeMarkerConfiguration {
53 @Bean
54 @ConditionalOnMissingBean
55 FreeMarkerLanguageDriver freeMarkerLanguageDriver() {
56 return new FreeMarkerLanguageDriver();
57 }
58 }
59
60
61
62
63 @Configuration(proxyBeanMethods = false)
64 @ConditionalOnClass({ FreeMarkerLanguageDriver.class, FreeMarkerLanguageDriverConfig.class })
65 public static class FreeMarkerConfiguration {
66 @Bean
67 @ConditionalOnMissingBean
68 FreeMarkerLanguageDriver freeMarkerLanguageDriver(FreeMarkerLanguageDriverConfig config) {
69 return new FreeMarkerLanguageDriver(config);
70 }
71
72 @Bean
73 @ConditionalOnMissingBean
74 @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".freemarker")
75 public FreeMarkerLanguageDriverConfig freeMarkerLanguageDriverConfig() {
76 return FreeMarkerLanguageDriverConfig.newInstance();
77 }
78 }
79
80
81
82
83 @Configuration(proxyBeanMethods = false)
84 @ConditionalOnClass(org.mybatis.scripting.velocity.Driver.class)
85 @ConditionalOnMissingClass("org.mybatis.scripting.velocity.VelocityLanguageDriverConfig")
86 @SuppressWarnings("deprecation")
87 public static class LegacyVelocityConfiguration {
88 @Bean
89 @ConditionalOnMissingBean
90 org.mybatis.scripting.velocity.Driver velocityLanguageDriver() {
91 return new org.mybatis.scripting.velocity.Driver();
92 }
93 }
94
95
96
97
98 @Configuration(proxyBeanMethods = false)
99 @ConditionalOnClass({ VelocityLanguageDriver.class, VelocityLanguageDriverConfig.class })
100 public static class VelocityConfiguration {
101 @Bean
102 @ConditionalOnMissingBean
103 VelocityLanguageDriver velocityLanguageDriver(VelocityLanguageDriverConfig config) {
104 return new VelocityLanguageDriver(config);
105 }
106
107 @Bean
108 @ConditionalOnMissingBean
109 @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".velocity")
110 public VelocityLanguageDriverConfig velocityLanguageDriverConfig() {
111 return VelocityLanguageDriverConfig.newInstance();
112 }
113 }
114
115 @Configuration(proxyBeanMethods = false)
116 @ConditionalOnClass(ThymeleafLanguageDriver.class)
117 public static class ThymeleafConfiguration {
118 @Bean
119 @ConditionalOnMissingBean
120 ThymeleafLanguageDriver thymeleafLanguageDriver(ThymeleafLanguageDriverConfig config) {
121 return new ThymeleafLanguageDriver(config);
122 }
123
124 @Bean
125 @ConditionalOnMissingBean
126 @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf")
127 public ThymeleafLanguageDriverConfig thymeleafLanguageDriverConfig() {
128 return ThymeleafLanguageDriverConfig.newInstance();
129 }
130
131
132 @SuppressWarnings("unused")
133 private static class MetadataThymeleafLanguageDriverConfig extends ThymeleafLanguageDriverConfig {
134
135 @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf.dialect")
136 @Override
137 public DialectConfig getDialect() {
138 return super.getDialect();
139 }
140
141 @ConfigurationProperties(CONFIGURATION_PROPERTY_PREFIX + ".thymeleaf.template-file")
142 @Override
143 public TemplateFileConfig getTemplateFile() {
144 return super.getTemplateFile();
145 }
146
147 }
148
149 }
150
151 }