InputStream in = getClass().getResourceAsStream('/'+"spring-beans.dtd"); 表示从classs目录下面的找文件,文件放在src下面就可以了.
InputStream in = getClass().getResourceAsStream("spring-beans.dtd"); 表示从当前classs下面的路径找文件
如果是在com.a.b.c.d.Test这个class就表示spring-beans.dtd要放在目录src\com\a\b\c\d下.
SAXBuilder builder = new SAXBuilder();
EntityResolver resolver = new EntityResolver() {
public InputSource resolveEntity(String publicId,
String systemId) {
if (publicId.equals("-//SPRING//DTD BEAN//EN")) {
InputStream in = getClass().getResourceAsStream(
'/'+"spring-beans.dtd");
return new InputSource(in);
} else {
return null;
}
}
};
builder.setEntityResolver(resolver);
这样才能解决dtd的本地查找问题.