mybatis/mybatis-3 · error · BuilderException
Please specify either 'value' or 'type' attribute of @{annot
Error message
Please specify either 'value' or 'type' attribute of @{annotationSimpleName} at the '{mapperMethod}'. What it means
Error "Please specify either 'value' or 'type' attribute of @{annotationSimpleName} at the '{mapperMethod}'." thrown in mybatis/mybatis-3.
Source
Thrown at src/main/java/org/apache/ibatis/builder/annotation/ProviderSqlSource.java:261
private String invokeProviderMethod(Object... args) throws Exception {
Object targetObject = null;
if (!Modifier.isStatic(providerMethod.getModifiers())) {
targetObject = providerType.getDeclaredConstructor().newInstance();
}
CharSequence sql = (CharSequence) providerMethod.invoke(targetObject, args);
return sql != null ? sql.toString() : null;
}
private Class<?> getProviderType(Configuration configuration, Annotation providerAnnotation, Method mapperMethod)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Class<?> type = (Class<?>) providerAnnotation.annotationType().getMethod("type").invoke(providerAnnotation);
Class<?> value = (Class<?>) providerAnnotation.annotationType().getMethod("value").invoke(providerAnnotation);
if (value == void.class && type == void.class) {
if (configuration.getDefaultSqlProviderType() != null) {
return configuration.getDefaultSqlProviderType();
}
throw new BuilderException("Please specify either 'value' or 'type' attribute of @"
+ providerAnnotation.annotationType().getSimpleName() + " at the '" + mapperMethod.toString() + "'.");
}
if (value != void.class && type != void.class && value != type) {
throw new BuilderException("Cannot specify different class on 'value' and 'type' attribute of @"
+ providerAnnotation.annotationType().getSimpleName() + " at the '" + mapperMethod.toString() + "'.");
}
return value == void.class ? type : value;
}
}
View on GitHub (pinned to 008069adb1)
Solutions
- Set either the value or the type attribute on the provider annotation to point at the SqlProvider class.
- Example: @SelectProvider(type = MyProvider.class, method = "provideSql").
When it happens
Trigger: Thrown at src/main/java/org/apache/ibatis/builder/annotation/ProviderSqlSource.java:261 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of mybatis/mybatis-3@008069adb1 (2026-08-14).
Data as JSON: /api/errors/e318abe75beabdd2.
Report an issue: GitHub.