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 java.io.IOException;
19 import java.util.Optional;
20 import java.util.Properties;
21 import java.util.stream.Stream;
22
23 import org.apache.ibatis.scripting.LanguageDriver;
24 import org.apache.ibatis.session.Configuration;
25 import org.apache.ibatis.session.ExecutorType;
26
27 import org.springframework.boot.context.properties.ConfigurationProperties;
28 import org.springframework.boot.context.properties.NestedConfigurationProperty;
29 import org.springframework.core.io.Resource;
30 import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
31 import org.springframework.core.io.support.ResourcePatternResolver;
32
33
34
35
36
37
38
39 @ConfigurationProperties(prefix = MybatisProperties.MYBATIS_PREFIX)
40 public class MybatisProperties {
41
42 public static final String MYBATIS_PREFIX = "mybatis";
43
44 private static final ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
45
46
47
48
49 private String configLocation;
50
51
52
53
54 private String[] mapperLocations;
55
56
57
58
59 private String typeAliasesPackage;
60
61
62
63
64
65 private Class<?> typeAliasesSuperType;
66
67
68
69
70 private String typeHandlersPackage;
71
72
73
74
75 private boolean checkConfigLocation = false;
76
77
78
79
80 private ExecutorType executorType;
81
82
83
84
85 private Class<? extends LanguageDriver> defaultScriptingLanguageDriver;
86
87
88
89
90 private Properties configurationProperties;
91
92
93
94
95
96 @NestedConfigurationProperty
97 private Configuration configuration;
98
99
100
101
102 public String getConfigLocation() {
103 return this.configLocation;
104 }
105
106
107
108
109 public void setConfigLocation(String configLocation) {
110 this.configLocation = configLocation;
111 }
112
113 public String[] getMapperLocations() {
114 return this.mapperLocations;
115 }
116
117 public void setMapperLocations(String[] mapperLocations) {
118 this.mapperLocations = mapperLocations;
119 }
120
121 public String getTypeHandlersPackage() {
122 return this.typeHandlersPackage;
123 }
124
125 public void setTypeHandlersPackage(String typeHandlersPackage) {
126 this.typeHandlersPackage = typeHandlersPackage;
127 }
128
129 public String getTypeAliasesPackage() {
130 return this.typeAliasesPackage;
131 }
132
133 public void setTypeAliasesPackage(String typeAliasesPackage) {
134 this.typeAliasesPackage = typeAliasesPackage;
135 }
136
137
138
139
140 public Class<?> getTypeAliasesSuperType() {
141 return typeAliasesSuperType;
142 }
143
144
145
146
147 public void setTypeAliasesSuperType(Class<?> typeAliasesSuperType) {
148 this.typeAliasesSuperType = typeAliasesSuperType;
149 }
150
151 public boolean isCheckConfigLocation() {
152 return this.checkConfigLocation;
153 }
154
155 public void setCheckConfigLocation(boolean checkConfigLocation) {
156 this.checkConfigLocation = checkConfigLocation;
157 }
158
159 public ExecutorType getExecutorType() {
160 return this.executorType;
161 }
162
163 public void setExecutorType(ExecutorType executorType) {
164 this.executorType = executorType;
165 }
166
167
168
169
170 public Class<? extends LanguageDriver> getDefaultScriptingLanguageDriver() {
171 return defaultScriptingLanguageDriver;
172 }
173
174
175
176
177 public void setDefaultScriptingLanguageDriver(Class<? extends LanguageDriver> defaultScriptingLanguageDriver) {
178 this.defaultScriptingLanguageDriver = defaultScriptingLanguageDriver;
179 }
180
181
182
183
184 public Properties getConfigurationProperties() {
185 return configurationProperties;
186 }
187
188
189
190
191 public void setConfigurationProperties(Properties configurationProperties) {
192 this.configurationProperties = configurationProperties;
193 }
194
195 public Configuration getConfiguration() {
196 return configuration;
197 }
198
199 public void setConfiguration(Configuration configuration) {
200 this.configuration = configuration;
201 }
202
203 public Resource[] resolveMapperLocations() {
204 return Stream.of(Optional.ofNullable(this.mapperLocations).orElse(new String[0]))
205 .flatMap(location -> Stream.of(getResources(location))).toArray(Resource[]::new);
206 }
207
208 private Resource[] getResources(String location) {
209 try {
210 return resourceResolver.getResources(location);
211 } catch (IOException e) {
212 return new Resource[0];
213 }
214 }
215
216 }