JBoss7中,如何设置自己的web的 web context为root context

1. application.xml

根据某个网页提示,

我们 把xxx.ear/META-INF/application.xml中web context设置为:

<?xml version=”1.0″ encoding=”UTF-8″?>
<application …>

<module>
<web>
<web-uri>ybxiang-forum-war.war</web-uri>
      <context-root>/</context-root>
</web>
</module>
</application>

日志显示错误:

14:46:52,671 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-3) JBAS010406: Registered connection factory java:/JmsXA
14:46:52,687 INFO  [org.jboss.as.jpa] (ServerService Thread Pool — 59) JBAS011402: Starting Persistence Unit Service ‘ybxiang-forum.ear/ybxiang-forum-ejb.jar#ybxiang-forum-persistence-unit’
14:46:52,750 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC00001: Failed to start service jboss.web.deployment.default-host./: org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./: Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.4.GA.jar:1.0.4.GA]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_15]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_15]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_15]
Caused by: java.lang.IllegalArgumentException: JBWEB000250: Child container with name  already exists
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:794)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:785)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:353)
at org.jboss.as.web.deployment.WebContextInjector.inject(WebContextInjector.java:62)
at org.jboss.as.web.deployment.WebContextInjector.inject(WebContextInjector.java:38)
at org.jboss.msc.inject.CastingInjector.inject(CastingInjector.java:55) [jboss-msc-1.0.4.GA.jar:1.0.4.GA]
at org.jboss.msc.service.ServiceControllerImpl.doInject(ServiceControllerImpl.java:1549) [jboss-msc-1.0.4.GA.jar:1.0.4.GA]
at org.jboss.msc.service.ServiceControllerImpl.access$1900(ServiceControllerImpl.java:49) [jboss-msc-1.0.4.GA.jar:1.0.4.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.performInjections(ServiceControllerImpl.java:1780) [jboss-msc-1.0.4.GA.jar:1.0.4.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1741) [jboss-msc-1.0.4.GA.jar:1.0.4.GA]
… 3 more

14:46:52,765 INFO  [org.hornetq.ra] (MSC service thread 1-3) HornetQ resource adaptor started

 

2. standalone.xml

我们搜索上述异常,找到 http://stackoverflow.com/questions/10081347/changing-context-root-for-a-web-app-under-jboss-as-7,根据其提示,把standalone.xml中的
<subsystem xmlns=”urn:jboss:domain:web:1.4″ default-virtual-server=”default-host” native=”false”>
<connector name=”http” protocol=”HTTP/1.1″ scheme=”http” socket-binding=”http”/>
<virtual-server name=”default-host” enable-welcome-root=”true“>
<alias name=”localhost”/>
<alias name=”example.com”/>
</virtual-server>
</subsystem>
中的enable-welcome-root=”true” 改成 enable-welcome-root=”false”

**********************************************************************************************

3. jboss-web.xml

如果你的应用程序只是一个war (而不是ear,从而没有application.xml),则可以在你的war应用程序的WEB-INF目录中,加上 jboss-web.xml配置文件,并如此配置:

<?xml version=”1.0″ encoding=”UTF-8″?>
<jboss-web>
<context-root>/</context-root>
</jboss-web>

如果你的应用程序是一个ear,那么通常不需要这么做,在xxx.ear/META-INF/application.xml中配置好<context-root/>就可以了(如1所描述)。

出處

Be the first to comment on "JBoss7中,如何设置自己的web的 web context为root context"

Leave a comment

Your email address will not be published.


*