在我使用 Gradle(Windows 7、Java 1.7.0.15)构建的现有项目中,我已经升级了 Mybatis 库,如下所示:
// MyBatis
compile "org.mybatis:mybatis:3.2.1"
compile "org.mybatis:mybatis-spring:1.2.0"
//compile "org.mybatis:mybatis:3.0.6"
//compile "org.mybatis:mybatis-spring:1.0.2"
现在,当我构建时,出现以下错误:
11:38:37.308 [INFO] [org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler]
Compiling with JDK 6 Java compiler API.
11:38:39.147 [ERROR] [system.err] ...java:14: error: DateTimeHandler is not abstract and does not override abstract method getNullableResult(ResultSet,int) in BaseTypeHandler
11:38:39.153 [ERROR] [system.err] public class DateTimeHandler extends BaseTypeHandler<DateTime> {
11:38:39.274 [ERROR] [system.err] Note: Some input files use or override a deprecated API.
11:38:39.279 [ERROR] [system.err] Note: Recompile with -Xlint:deprecation for details.
11:38:39.284 [ERROR] [system.err] 1 error
我已经检查了这个类一百次,它确实覆盖了正确的方法(事实上 Eclipse 同意它没有显示错误)。
我不知道为什么在一切都应该在 Java 7 之下时使用内部 Gradle 类 jdk6。有人知道这里发生了什么 id 吗?
Gradle 不喜欢的类:
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedTypes;
import org.joda.time.DateTime;
@MappedTypes(value = DateTime.class)
public class DateTimeHandler extends BaseTypeHandler<DateTime> {
public DateTimeHandler() {
}
@Override
public void setNonNullParameter(PreparedStatement ps, int i, DateTime parameter, JdbcType jdbcType) throws SQLException {
ps.setTimestamp(i, new java.sql.Timestamp((parameter.toDate()).getTime()));
}
@Override
public DateTime getNullableResult(ResultSet rs, String columnName) throws SQLException {
java.sql.Timestamp sqlTimestamp = rs.getTimestamp(columnName);
if (sqlTimestamp != null) {
return new DateTime(sqlTimestamp.getTime());
}
return null;
}
@Override
public DateTime getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
java.sql.Timestamp sqlTimestamp = cs.getTimestamp(columnIndex);
if (sqlTimestamp != null) {
return new DateTime(sqlTimestamp.getTime());
}
return null;
}
}
但据我所知,它没有任何问题。正确的方法被覆盖。
确定修复了构建:
在方法中添加:
public DateTime getNullableResult(ResultSet rs, int columnIndex) 抛出 SQLException;
如果我在此方法上使用覆盖注释,但没有注释 Gradle 构建成功完成,则会出现 Eclipse 错误。如果该方法被删除,Gradle 会产生一个错误,指出该类需要覆盖具有该签名的方法(或被声明为抽象)。
因此,尽管我的问题已解决,但我并不真正了解此错误的性质。