Persistence Unit Service starting multille times - maven

I am having EAR project which contains 1 EJB 3.0 Project and 2 WAR Project.
I have defined persistence.xml in my EJB project.
However when the application starts it starts persistence unit service 3 times.
As per log on startup I can see
Starting Persistence Unit Service 'xyz-ear.ear/xyz-ejb-1_0_0-SNAPSHOT.jar#xyzUnit'
Starting Persistence Unit Service 'xyz-ear.ear/xyz-war-1_0_0-SNAPSHOT.war#xyzUnit'
Starting Persistence Unit Service 'xyz-ear.ear/xyz-service-war-1_0_0-SNAPSHOT.war#xyzUnit'
Beacuse of this my database schema validation is happening 3 times.
#Startup
#Singleton
#PostConstruct
is getting called 3 times.
Has anyone faced this issue before?
Please let me know if you need any other info.
PS: I have declared the EJB as ejb and not as ejb-client in pom.xml of both war module.
Can that cause this issue ?

Related

Springboot application getting Conflicting persistence unit definition for name default

In my spring boot application, I am using some jar files which have inner jars.Those inner jars have separate persistence.xml file and using default as persistence unit name. Now while I am trying to run my spring boot application, I am getting conflicting persistence unit definition for name default. Does somebody know how to resolve this?

Singleton EJB not found

I've an EAR with an EJB and WAR project in it. I use Netbeans and the Maven building tool. In my EJB there is one EJB, a singleton class: http://pastebin.com/f8jXw0TK
Here is a screenshot of my project structure in Netbeans: https://gyazo.com/09e075972279f637de2d4d98fe9a1ac7
When I deploy the EAR or the EJB-JAR in Glassfish (localhost). I get the follow error message:
Error occurred during deployment: Exception while deploying the app [arp-auth-business-1.0] : Invalid ejb jar [arp-auth-business-1.0]: it contains zero ejb. Note: 1. A valid ejb jar requires at least one session, entity (1.x/2.x style), or message-driven bean. 2. EJB3+ entity beans (#Entity) are POJOs and please package them as library jar. 3. If the jar file contains valid EJBs which are annotated with EJB component level annotations (#Stateless, #Stateful, #MessageDriven, #Singleton), please check server.log to see whether the annotations were processed properly.. Please see server.log for more details.
I've added a simple stateless bean to the EJB JAR, and then it deployed. But then I saw just the simple stateless bean I created, but not my singleton class.
What could be wrong? The server.log shows the same error I get in Glassfish but with a exception stack from the loader. No error from the singleton class or something like that...
Still trying but can't figure it out. Maybe it's maven? But the jar and war file are in the ear file. And in the jar file there is my singleton class.
Kind regards

EJB3 initialization code

I've searched this for a while now, but can't seem to find an answer to this. How can I execute some code in when deploying an EJB3 jar-file to a JBoss server? For example, I need to run some sql migration scripts before the beans are ready to be used.
If you can't use EJB 3.1 (with #Singleton #Startup), I would recommend packaging your EJB module in an EAR with a WAR. Add a ServletContextListener to the WAR, and take your action in the contextInitialized method.
You can create a JBoss MBean service with a Listener that can perform any initialization (SQL scripts run in your case) after JBoss is fully started and before any EJB is used.
I have created such a service and we run it on JBoss 4.2.3.GA, so, you do not need to migrate to JBoss 7.

FileNotFoundException in a testing a Maven module

I'm working on a recently mavenized legacy project with following multi-modular structure:
Parent:
Web
Service
Dao
("Service" module is dependent on "Dao" module)
Problem: some tests of Service classes call DAO code that creates beans using Spring's ClassPathXmlApplicationContext (this part is not really DAOs but caching related). Since, ClassPathXmlApplicationContext uses spring config xml of the DAO module - the Service tests fail throwing FileNotFoundException. I think this is because tests run in Service module and the spring config xml being referred lies in Dao module.
Please advise on how can I resolve the above issue in tests referring to code/resources of other modules?
Put a copy of the Spring configuration under src/test/resources in the Service module. Quite often you want a different configuration for testing anyway, but also it means your tests are less dependent on configuration changes in another module.

How to setup a Spring multimodule project?

I'm new to Spring and try to setup a project which is split into 3 submodules. As build tool I'm using maven. My problem is, that I don't know where to add Springs "magic".
My 3 submodules are "ORM" (holds all the hibernate staff to access the database) "BusinessLogic" (which should hold the complete logic) and "WebApp" (adds as the only "client" to the app / logic).
I want to use SpringMVC for the WebApp which seems to be no problem. As "BusinessLogic" should hold the complete logic I thought of adding the Spring related stuff (Bean definition / DI) in that module. But then I don't know how to setup Spring when accessing the module form the webapp.
The hole project is being ported from a JavaEE / JBoss app where "ORM" and "BusinessLogic" (implemented as EJBs) where put into one .ear archive and the webapp into a seperate one (.war). JNDI was used to access the beans from the webapp, but I completely want to decouple the application from JBoss and deploy it on a Tomcat webserver.
At the moment I've created all three modules as separate Maven projects ("ORM" and "BusinessLogic" as .jar, "WebApp" as .war packaging), linked by a "parent" project.
Thanks for any hints on project setup :).
Greetings
Ben
you could configure spring context in your web.xml and you can perform import of Spring sub-modules context. You can add import's configuration of sub-modules in your webApp application context.

Resources