在具有多个数据源的JBOSS上部署应用程序时出现问题

时间:2019-03-19 01:49:18

标签: java spring-boot jboss datasource jndi

嗨,我正在尝试在JBOSS EAP 7.1上部署两个war文件。 这两个都是我配置了JNDI查找的Spring Boot应用程序。 我的Standalone.xml文件看起来像这样。

 <datasources>
            <datasource jndi-name="java:/JNDI1" pool-name="JNDIPool1" enabled="true" use-java-context="true">
                <connection-url>jdbc:mysql://localhost:3306/test_schema</connection-url>
                <driver>mysql</driver>
                <security>
                    <user-name>test1</user-name>
                    <password>test1</password>
                </security>
            </datasource>
            <datasource jndi-name="java:/JNDI2" pool-name="JNDIPool2" enabled="true" use-java-context="true">
                <connection-url>jdbc:mysql://localhost:3306/test_schema_2</connection-url>
                <driver>mysql</driver>
                <security>
                    <user-name>test2</user-name>
                    <password>test2</password>
                </security>
            </datasource>
            <drivers>
                <driver name="mysql" module="com.mysql"/>
            </drivers>
        </datasources>

每个战争文件使用不同的JNDI查找。当我同时部署它们时,其中一个战争被部署,而另一个战争失败,并出现以下错误。任何帮助,将不胜感激。 谢谢。

     ERROR [org.jboss.msc.service.fail] (MSC service thread 1-8) MSC000001: Failed to start service jboss.deployment.unit."Test.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."TEST.war".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of deployment "TEST.war"
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:172)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:2032)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1955)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.jboss.msc.service.DuplicateServiceException: Service jboss.undertow.deployment.default-server.default-host./.session is already registered
    at org.jboss.msc.service.ServiceRegistrationImpl.setInstance(ServiceRegistrationImpl.java:158)
    at org.jboss.msc.service.ServiceControllerImpl.startInstallation(ServiceControllerImpl.java:235)
    at org.jboss.msc.service.ServiceContainerImpl.install(ServiceContainerImpl.java:768)
    at org.jboss.msc.service.ServiceTargetImpl.install(ServiceTargetImpl.java:223)
    at org.jboss.msc.service.ServiceControllerImpl$ChildServiceTarget.install(ServiceControllerImpl.java:2555)
    at org.jboss.msc.service.ServiceTargetImpl.install(ServiceTargetImpl.java:223)
    at org.jboss.msc.service.ServiceControllerImpl$ChildServiceTarget.install(ServiceControllerImpl.java:2555)
    at org.jboss.msc.service.ServiceBuilderImpl.install(ServiceBuilderImpl.java:317)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentProcessor.lambda$processDeployment$0(UndertowDeploymentProcessor.java:405)
    at java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)
    at java.util.stream.ReferencePipeline$Head.forEach(Unknown Source)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentProcessor.processDeployment(UndertowDeploymentProcessor.java:405)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentProcessor.deploy(UndertowDeploymentProcessor.java:190)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:165)
    ... 5 more

1 个答案:

答案 0 :(得分:2)

请为web.xml中的每个应用程序分配不同的上下文根。我猜您正在使用默认的<context-root>/</context-root>,从而导致DuplicateServiceException引起第二次战争。将其更改为<context-root>/app1</context-root><context-root>/app2</context-root>