spring "persistence.xml" file location - spring

Developing web application under STS 3.4.0.RELEASE (Spring). I have working JPA example under Eclipse Juno and want to port it as part of Spring application. I have to copy persistence.xml file. Where should it be located exactly?
So far I get "javax.persistence.PersistenceException: No Persistence provider for EntityManager named ..." which may be related to location or may be not.
Is there a need for "provider" element and if so what should be the value? (It worked fine under Eclipse without that element).
Please Help!!!

Your persistence.xml is not valid and the EntityManagerFactory can't get created
Refer this similar question Cause of this Exception
Hope it helps..

The persistence.xml file should be placed in META-INF/persistence.xml in your classpath.

Related

What happens to the "application.properties" file when a spring boot application is built

I am trying to understand what Spring Boot does with the "application.properties" file. I know it configures the application, but when I look inside the final JAR file gradle creates (its spring boot+gradle), I cannot find the application.properties file.
My applications works fine. But I'm curious what happens to the application.properties when the application is built and how my configurations finds its way in to the application. Can someone shed light on this?
Thanks in advance.

Spring Security-Reload my security.xml on edit

I am using Spring Security in my project. I have a situation where I need to change the pattern attribute in itercept-url tag on runtime. For this I have to again restart the tomcat server and in turn takes a lot of time for me to test my changes.
Does Spring have a solution where the security.xml file is reloaded when I edit it in my web application, without restarting my server. Please provide some pointers for the same as I am new to Spring Framework.
Any link to a step by step tutorial will certainly help a lot.
Thanks in advance.
Divyang Agrawal
Use spring annotation rather than using xml configuration. so by using annotation you do not required tomcat restart after changing the source code.
you can find simple tutorial for how to use annotation based spring security here Link

How to configure datasource in persistence.xml file itself?

The answer of this question will be very helpful for me to resolve my previous question.
here.
I am trying simple Spring-MVC (with JPA) application. I want to include every necessary connection values in persistence.xml file only. In my application there are only 2 XMl files.
1) web.xml and 2) persistence.xml
Please check my previous question ( here.) for errors and persistence.xml file.
I am searching on net but not getting proper answer.
Please help me. Thank you very much in advance.
If you are using Spring / springMVC then you need to configure the datasource in the spring application context xml file only. All your contents from persistence.xml should be placed in the spring application context xml. Because spring is the core base framework which manages hibernate.
Check this http://viralpatel.net/blogs/spring3-mvc-hibernate-maven-tutorial-eclipse-example/
In this example its configured in spring-servlet.xml

Maven web project with JPA, Spring, Hibernate

I am getting started with with JPA. I am not running the project in a JEE container, simply using Tomcat. I want to test my DAOs (even though I read somewhere that DAOs may not be relevant with ORMs today) and have minimal dependencies on Spring and Hibernate.
Gist for relevant codes and configuration.
Problems I am facing are
bean of type UserDao cannot be found and hence cannot be injected resulting in error, even though I can see that it is created as it's constructor runs and I have done syso there, BUT
EntityManager is Null when UserDao is initialized
If I change the test-config.xml to use persistence.xml which is configured for MySQL database, it creates all tables, but same errors. hsqldb-persistence.xml is configured to use in-memory db.
Project Structure as it appears in Eclipse. When I run the TestUserDao it read correctly everything from hsqldb-persistence.xml which is in /src/test/java/resources/WEB-INF/ directory.
Appreciate any help.
Thankyou.

NoSuchBeanDefinitionException for annotated classess alone

Am getting org.springframework.beans.factory.NoSuchBeanDefinitionException
for the Classes for which I have used annotation (#Service)
I have mentioned the package scan correctly
This is a blunder mistake in deed. But just posting the answer because, many might do the same.
I was using Eclipse to prepare the JAR file. Eclipse did not pack the class files properly, so spring could not load the beans

Resources