简体   繁体   中英

Web app on EC2 instance doesn't seem to load persistence.xml

I have an instance of EC2 on which I've deployed a web application. The EC2 instance is Linux with Tomcat. The web app works just fine locally on my box, and it connects to an AWS RDS instance of MySQL.

When I deploy this web app to the EC2 instance, any page that requires a call to the DB doesn't load. I'm using Hibernate and at the point where I try to get a Hibernate session created, I get a NullPointerException. This is the same error I get on my local box if I delete the persistence.xml config file.

Inside my persistence.xml, I simply have a persistence-unit defined, as you would expect. Nothing fancy (and again, it works fine locally).

Why is persistence.xml config file not being found/discovered and loaded when the app runs on the EC2 instance?

Currently the config file is located here in the project:

/web/res/META-INF/persistence.xml

Any input is appreciated. Thanks!

Try to copy the META-INF folder with your persistence.xml to your src folder. I've had problems before where I couldn't load my persistence.xml because it wasn't in my classpath.

Ok, so I'm an idiot. I had the MySQL connector jar in the tomcat lib directory, so that all my projects automatically get to make use of it w/o me manually adding it to each project. But when you wrap stuff up in a war file and publish, it doesn't include those 'common' jars. As a side note, shouldn't those jars be included in the war? Seems strange to me that they aren't.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM