Redeploy dependent WAR fails with duplicate resource error for persistence unit
jasonholmberg Dec 18, 2015 10:51 AMThis is essentially the same described in Redeploy dependent ear fails with duplicate resource error for persistence unit by specifically focusing on web deployments.
This example consists of two simple web apps: App1 and App2. They both initially deploy cleanly. In this example App2 depends on App1 with this dependency defined in a jboss-deployment-structure.xml file, list below:
<?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1"> <deployment> <dependencies> <module name="deployment.app1.war" /> </dependencies> </deployment> </jboss-deployment-structure>
App2 also has a simple, do-nothing Persistence Unit name MyPU:
<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="MyPU" transaction-type="JTA"> <properties> <!-- nothing here --> </properties> </persistence-unit> </persistence>
This is the log output at start up:
08:14:39,440 INFO [org.jboss.as.repository] (DeploymentScanner-threads - 2) - WFLYDR0001: Content added at location C:\Servers\wildfly-9.0.2.Final\standalone\data\content\82\a283014519aca7a2682f13f1e7765ba306339b\content 08:14:39,448 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) - WFLYSRV0027: Starting deployment of "app1.war" (runtime-name: "app1.war") 08:14:39,605 INFO [org.jboss.weld.deployer] (MSC service thread 1-3) - WFLYWELD0003: Processing weld deployment app1.war 08:14:39,657 INFO [org.hibernate.validator.internal.util.Version] (MSC service thread 1-3) - HV000001: Hibernate Validator 5.1.3.Final 08:14:39,755 INFO [org.jboss.weld.deployer] (MSC service thread 1-3) - WFLYWELD0006: Starting Services for CDI deployment: app1.war 08:14:39,789 INFO [org.jboss.weld.Version] (MSC service thread 1-3) - WELD-000900: 2.2.16 (SP1) 08:14:39,799 INFO [org.jboss.weld.deployer] (MSC service thread 1-3) - WFLYWELD0009: Starting weld service for deployment app1.war 08:14:40,431 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 14) - WFLYUT0021: Registered web context: /app1 08:14:40,619 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) - WFLYSRV0010: Deployed "app1.war" (runtime-name : "app1.war") 08:14:45,668 INFO [org.jboss.as.repository] (DeploymentScanner-threads - 2) - WFLYDR0001: Content added at location C:\Servers\wildfly-9.0.2.Final\standalone\data\content\56\525fec6e815870ce58cf71a6eafb8515dad271\content 08:14:45,673 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) - WFLYSRV0027: Starting deployment of "app2.war" (runtime-name: "app2.war") 08:14:45,726 INFO [org.jboss.as.jpa] (MSC service thread 1-5) - WFLYJPA0002: Read persistence.xml for MyPU 08:14:45,755 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 14) - WFLYJPA0010: Starting Persistence Unit (phase 1 of 2) Service 'app2.war#MyPU' 08:14:45,758 INFO [org.jboss.weld.deployer] (MSC service thread 1-7) - WFLYWELD0003: Processing weld deployment app2.war 08:14:45,797 INFO [org.hibernate.jpa.internal.util.LogHelper] (ServerService Thread Pool -- 14) - HHH000204: Processing PersistenceUnitInfo [ name: MyPU ...] 08:14:45,871 INFO [org.hibernate.Version] (ServerService Thread Pool -- 14) - HHH000412: Hibernate Core {4.3.10.Final} 08:14:45,873 INFO [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 14) - HHH000206: hibernate.properties not found 08:14:45,875 INFO [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 14) - HHH000021: Bytecode provider name : javassist 08:14:45,904 INFO [org.jboss.weld.deployer] (MSC service thread 1-2) - WFLYWELD0006: Starting Services for CDI deployment: app2.war 08:14:45,909 INFO [org.jboss.weld.deployer] (MSC service thread 1-5) - WFLYWELD0009: Starting weld service for deployment app2.war 08:14:45,919 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 14) - WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'app2.war#MyPU' 08:14:45,982 INFO [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 14) - HCANN000001: Hibernate Commons Annotations {4.0.5.Final} 08:14:46,211 INFO [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 14) - HHH000400: Using dialect: org.hibernate.dialect.SQLServer2008Dialect 08:14:46,244 INFO [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (ServerService Thread Pool -- 14) - HHH000397: Using ASTQueryTranslatorFactory 08:14:46,522 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 6) - WFLYUT0021: Registered web context: /app2 08:14:46,680 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) - WFLYSRV0010: Deployed "app2.war" (runtime-name : "app2.war")
Things breakdown when you redeploy App1 (the app the App2 has delcared a dependency on), this is the result:
08:27:33,315 INFO [org.jboss.as.repository] (DeploymentScanner-threads - 1) - WFLYDR0001: Content added at location C:\Servers\wildfly-9.0.2.Final\standalone\data\content\89\cb02842c45df9b8bb05056a2eb2c82809d2dbf\content 08:27:33,328 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 68) - WFLYUT0022: Unregistered web context: /app2 08:27:33,329 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 67) - WFLYUT0022: Unregistered web context: /app1 08:27:33,354 INFO [org.jboss.weld.deployer] (MSC service thread 1-3) - WFLYWELD0010: Stopping weld service for deployment app1.war 08:27:33,354 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 70) - WFLYJPA0011: Stopping Persistence Unit (phase 2 of 2) Service 'app2.war#MyPU' 08:27:33,356 INFO [org.jboss.weld.deployer] (MSC service thread 1-7) - WFLYWELD0010: Stopping weld service for deployment app2.war 08:27:33,357 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 70) - WFLYJPA0011: Stopping Persistence Unit (phase 1 of 2) Service 'app2.war#MyPU' 08:27:33,380 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) - WFLYSRV0028: Stopped deployment app1.war (runtime-name: app1.war) in 59ms 08:27:33,382 INFO [org.jboss.as.server.deployment] (MSC service thread 1-5) - WFLYSRV0027: Starting deployment of "app1.war" (runtime-name: "app1.war") 08:27:33,420 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) - WFLYSRV0070: Deployment restart detected for deployment app2.war, performing full redeploy instead. 08:27:33,425 INFO [org.jboss.weld.deployer] (MSC service thread 1-5) - WFLYWELD0003: Processing weld deployment app1.war 08:27:33,441 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) - WFLYSRV0028: Stopped deployment app2.war (runtime-name: app2.war) in 19ms 08:27:33,442 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) - WFLYSRV0027: Starting deployment of "app2.war" (runtime-name: "app2.war") 08:27:33,476 INFO [org.jboss.as.jpa] (MSC service thread 1-7) - WFLYJPA0002: Read persistence.xml for MyPU 08:27:33,485 INFO [org.jboss.weld.deployer] (MSC service thread 1-5) - WFLYWELD0006: Starting Services for CDI deployment: app1.war 08:27:33,488 INFO [org.jboss.weld.deployer] (MSC service thread 1-5) - WFLYWELD0009: Starting weld service for deployment app1.war 08:27:33,490 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 70) - WFLYJPA0010: Starting Persistence Unit (phase 1 of 2) Service 'app2.war#MyPU' 08:27:33,491 INFO [org.hibernate.jpa.internal.util.LogHelper] (ServerService Thread Pool -- 70) - HHH000204: Processing PersistenceUnitInfo [ name: MyPU ...] 08:27:33,494 INFO [org.jboss.weld.deployer] (MSC service thread 1-7) - WFLYWELD0003: Processing weld deployment app2.war 08:27:33,602 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-8) - MSC000001: Failed to start service jboss.deployment.unit."app2.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."app2.war".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of deployment "app2.war" at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:163) [wildfly-server-1.0.2.Final.jar:1.0.2.Final] at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.6.Final.jar:1.2.6.Final] at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.6.Final.jar:1.2.6.Final] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_51] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_51] at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_51] Caused by: java.lang.IllegalStateException: WFLYCTL0075: Duplicate resource app2.war#MyPU at org.jboss.as.controller.registry.AbstractModelResource$DefaultResourceProvider.register(AbstractModelResource.java:248) at org.jboss.as.controller.registry.AbstractModelResource.registerChild(AbstractModelResource.java:143) at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.addManagementConsole(PersistenceUnitServiceHandler.java:1128) at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.deployPersistenceUnitPhaseTwo(PersistenceUnitServiceHandler.java:704) at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.addPuService(PersistenceUnitServiceHandler.java:289) at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.handleWarDeployment(PersistenceUnitServiceHandler.java:200) at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.deploy(PersistenceUnitServiceHandler.java:131) at org.jboss.as.jpa.processor.PersistenceCompleteInstallProcessor.deploy(PersistenceCompleteInstallProcessor.java:55) at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:156) [wildfly-server-1.0.2.Final.jar:1.0.2.Final] ... 5 more 08:27:33,657 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 70) - WFLYUT0021: Registered web context: /app1 08:27:34,009 INFO [org.jboss.as.server] (DeploymentScanner-threads - 1) - WFLYSRV0016: Replaced deployment "app1.war" with deployment "app1.war" 08:27:34,010 INFO [org.jboss.as.controller] (DeploymentScanner-threads - 1) - WFLYCTL0183: Service status report WFLYCTL0184: New missing/unsatisfied dependencies: service jboss.deployment.unit."app2.war".beanmanager (missing) dependents: [service jboss.deployment.unit."app2.war".weld.weldClassIntrospector, service jboss.deployment.unit."app2.war".batch.environment] WFLYCTL0186: Services which failed to start: service jboss.deployment.unit."app2.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."app2.war".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of deployment "app2.war"
It looks like WildFly is really trying to deploy the apps, but there is a lot of deployment stopping and starting going on and it seems that the stopping of the persistence unit get lost in there someplace or it gets stopped and then started again and then not stopped again and then when WildFly logs this:
08:27:33,420 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) - WFLYSRV0070: Deployment restart detected for deployment app2.war, performing full redeploy instead.
It is trying to really deploy app2 and it tries to start the Persistence Unit again and that is when app2 finally fails. Browsing to the applications results in a 404, but in the deployments directory the marker file still reads app2.war.deployed.
Also, I have tested this in WildFly 8.2.0, 8.2.1, 9.0.1, and 9.0.2 all fail in the same way.
Has anyone determined a work-around for this bug that is better than redeploying App2? We have a number of applications that rely on this sort of dependency. It may not be the best configuration, but it is something we have to live with until we have the cycles to change.
The code for the sample applications is here: slowtrailrunner/wildfly-deployment-dependency · GitHub
Thanks,
Jason