Skip to content

Commit 8817d47

Browse files
committed
Add wanring log for the deprecated property
See gh-66
1 parent 620ecdb commit 8817d47

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/main/java/org/mybatis/scripting/velocity/VelocityLanguageDriverConfig.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
import org.apache.commons.text.WordUtils;
3838
import org.apache.ibatis.io.Resources;
39+
import org.apache.ibatis.logging.Log;
40+
import org.apache.ibatis.logging.LogFactory;
3941
import org.apache.ibatis.reflection.DefaultReflectorFactory;
4042
import org.apache.ibatis.reflection.MetaObject;
4143
import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
@@ -71,6 +73,8 @@ public class VelocityLanguageDriverConfig {
7173
TYPE_CONVERTERS = Collections.unmodifiableMap(converters);
7274
}
7375

76+
private static final Log log = LogFactory.getLog(VelocityLanguageDriverConfig.class);
77+
7478
/**
7579
* The Velocity settings.
7680
*/
@@ -123,6 +127,8 @@ public String[] getUserdirective() {
123127
*/
124128
@Deprecated
125129
public void setUserdirective(String... userDirectives) {
130+
log.warn(
131+
"The 'userdirective' has been deprecated since 2.1.0. Please use the 'velocity-settings.runtime.custom_directives' or 'runtime.custom_directives'.");
126132
this.userDirectives = userDirectives;
127133
}
128134

@@ -270,6 +276,9 @@ private static void override(VelocityLanguageDriverConfig config, Properties pro
270276
private static void enableLegacyAdditionalContextAttributes(Properties properties) {
271277
String additionalContextAttributes = properties.getProperty(PROPERTY_KEY_ADDITIONAL_CONTEXT_ATTRIBUTE);
272278
if (Objects.nonNull(additionalContextAttributes)) {
279+
log.warn(String.format(
280+
"The '%s' has been deprecated since 2.1.0. Please use the 'additionalContextAttributes.{name}={value}'.",
281+
PROPERTY_KEY_ADDITIONAL_CONTEXT_ATTRIBUTE));
273282
Stream.of(additionalContextAttributes.split(",")).forEach(pair -> {
274283
String[] keyValue = pair.split(":");
275284
if (keyValue.length != 2) {

src/test/resources/log4j.properties

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# Copyright 2012-2019 the original author or authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
### Global logging configuration
18+
log4j.rootLogger=ERROR, stdout
19+
20+
### Uncomment for MyBatis logging
21+
log4j.logger.org.mybatis.scripting.velocity=trace
22+
23+
### Console output...
24+
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
25+
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
26+
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

0 commit comments

Comments
 (0)