Skip to content

Commit 6b9e733

Browse files
committed
fix for http://code.google.com/p/mybatis/issues/detail?id=148 . Fail during startup if provider method is not found.
1 parent 62b56f3 commit 6b9e733

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/main/java/org/apache/ibatis/builder/annotation/ProviderSqlSource.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ public class ProviderSqlSource implements SqlSource {
1616
private boolean providerTakesParameterObject;
1717

1818
public ProviderSqlSource(Configuration config, Object provider) {
19+
String providerMethodName = null;
1920
try {
2021
this.sqlSourceParser = new SqlSourceBuilder(config);
2122
this.providerType = (Class<?>) provider.getClass().getMethod("type").invoke(provider);
22-
String providerMethod = (String) provider.getClass().getMethod("method").invoke(provider);
23+
providerMethodName = (String) provider.getClass().getMethod("method").invoke(provider);
2324

24-
for (Method m : providerType.getMethods()) {
25-
if (providerMethod.equals(m.getName())) {
25+
for (Method m : this.providerType.getMethods()) {
26+
if (providerMethodName.equals(m.getName())) {
2627
if (m.getParameterTypes().length < 2
2728
&& m.getReturnType() == String.class) {
2829
this.providerMethod = m;
@@ -33,6 +34,10 @@ public ProviderSqlSource(Configuration config, Object provider) {
3334
} catch (Exception e) {
3435
throw new BuilderException("Error creating SqlSource for SqlProvider. Cause: " + e, e);
3536
}
37+
if (this.providerMethod == null) {
38+
throw new BuilderException("Error creating SqlSource for SqlProvider. Method '"
39+
+ providerMethodName + "' not found in SqlProvider '" + this.providerType.getName() + "'.");
40+
}
3641
}
3742

3843
public BoundSql getBoundSql(Object parameterObject) {

0 commit comments

Comments
 (0)