我得到了错误Unable to locate NamespaceHandler when using context:annotation-config运行(java -jar)一个由maven-assembly-plugin组装并包含我的项目及其所有依赖项的jar.
正如其他人在forum.springsource.org 线程(消息#7/8)上正确发现的那样,问题出现是因为文件META-INF/spring.handlers和META-INF/spring.schemas存在于不同的jar中,当maven-assembly-plugin在单个文件中重新打包jar时会被覆盖.
查看两个spring - *.jar文件的内容,您可以看到文件位于相对于类路径的相同位置
$ jar tf spring-oxm-3.0.3.RELEASE.jar
META-INF/spring.handlers
META-INF/spring.schemas
org/springframework/oxm/GenericMarshaller.class
...
$ jar tf spring-context-3.0.3.RELEASE.jar
META-INF/spring.handlers
META-INF/spring.schemas
org/springframework/context/ApplicationContext.class
Run Code Online (Sandbox Code Playgroud)
是不是可以将META-INF文件夹放在特定的包中?如果是这样,我建议的想法(希望它是适用的)是将META-INF/spring.shemas和META-INF/spring.handlers文件放在他们引用的包下面.
$ jar tf spring-oxm-3.0.3.RELEASE.jar
org/springframework/oxm/META-INF/spring.schemas
org/springframework/oxm/META-INF/spring.handlers
org/springframework/oxm/GenericMarshaller.class
...
$ jar tf spring-context-3.0.3.RELEASE.jar
org/springframework/context/META-INF/spring.handlers
org/springframework/context/META-INF/spring.schemas
org/springframework/context/ApplicationContext.class
Run Code Online (Sandbox Code Playgroud)
这样,在单个jar中合并时它们不会发生冲突.你怎么看待这件事?
public class ReportView extends JFrame {
Connection con=null;
void showReport() throws SQLException, ClassNotFoundException, JRException {
con=DriverManager.getConnection("jdbc:postgresql://localhost:5432/Test");
JasperReport report=JasperCompileManager.compileReport("Testing.jrxml");
JasperPrint print=JasperFillManager.fillReport(report,null,con);
JRViewer viewer=new JRViewer(print);
viewer.setOpaque(true);
viewer.setVisible(true);
this.add(viewer);
this.setSize(300, 200);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
Run Code Online (Sandbox Code Playgroud)
这是错误:
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost:5432/Test
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
怎么了?