Tomcat webapp silently fails
I have a Tomcat webapp that uses Hibernation Configuration, the code below silently fails
at Configuration cfg = new Configuration();
Tomcat logs are not giving any error except my debugging statement right below where it fails (BEGIN STATIC!!!). No exception is thrown.
However when I packed the app into a jar, and runs the same method call in the main, it succeeds without error.
public class Manager {
static Logger log = Logger.getLogger(Manager.class);
public static SessionFactory sessionFactory;
public static void main(String[]args){
System.out.println(getSessionFactory());
}
public static SessionFactory getSessionFactory(){
if(sessionFactory==null){
System.out.println("BEGIN STATIC!!!!!!!! ");
try{
Configuration cfg = new Configuration(); //FAILS SILENTLY
System.out.println("BEGIN STATIC1"); //NOT PRINTED THEREAFTER
cfg.configure("hibernate_xxx.xml");
System.out.println("BEGIN S开发者_如何学PythonTATIC2");
cfg.addResource("xxx/persistence/xxx.xml");
System.out.println("BEGIN STATIC 3");
cfg.addResource("xxx/persistence/xxx.hbm.xml");
cfg.addResource("xxx/persistence/xxx.hbm.xml");
sessionFactory = cfg.buildSessionFactory();
}catch(Exception exp){
System.out.println("ERROR");
exp.printStackTrace(System.out);
}
System.out.println("END STATIC ");
}
return sessionFactory;
}
Try adding the following after your other catch:
catch(Error e){
e.printStackTrace();
}
Probably an error was thrown instead of an exception. Then at least you should get an error message instead of nothing.
精彩评论