I would like to deploy my JHipster app in JBoss AS 7.2.0 with a webapp context. First I have added a jboss-deployment-structure.xml
file to allow the deployment and to resolve conflicts between JBoss libraries and applicatin libraries :
我想把我的JHipster应用程序在JBoss中部署为7.2.0,使用webapp上下文。首先,我添加了一个jboss- deploytionstructure。允许部署和解决JBoss库和应用程序库之间的冲突的xml文件:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<dependencies>
<!-- Add some dependencies because of javaee.api exclusion -->
<module name="javax.xml.bind.api" />
<module name="javax.xml.ws.api" />
<module name="javax.jws.api" />
<module name="javax.annotation.api" />
</dependencies>
<exclude-subsystems>
<subsystem name="webservices" />
<subsystem name="jaxrs" />
<subsystem name="jpa" />
</exclude-subsystems>
<exclusions>
<module name="org.slf4j" />
<module name="org.slf4j.impl" />
<module name="org.slf4j.jcl-over-slf4j" />
<module name="org.apache.commons.logging" />
<module name="org.jboss.logging" />
<module name="org.apache.log4j" />
<module name="javaee.api" />
</exclusions>
</deployment>
</jboss-deployment-structure>
To add a webapp context, I have added a jboss-web.xml
:
为了添加一个webapp上下文,我添加了一个jboss-web。xml:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>myapp</context-root>
</jboss-web>
So, I can go to http://localhost:8080/myapp
to see the main page, but REST requests fail. The requests are sent to http://localhost:8080/app/rest
... instead of http://localhost:8080/myapp/app/rest
... (Even If i try with the webapp context in the URL, a 404 error occurs)
因此,我可以访问http://localhost:8080/myapp查看主页,但REST请求失败。请求被发送到http://localhost:8080/app/rest…而不是http://localhost:8080 / myapp / app /休息…(即使我在URL中尝试了webapp上下文,也会出现404错误)
I tried to remove jboss-web.xml and to deploy a myapp.war file, now the request are done with the context path (http://localhost:8080/myapp/app/rest
) but always with a 404 error. I have renamed the file as ROOT.war, but the behaviour is the same :(
我试图删除jboss-web。xml和部署myapp。war文件,现在请求是通过上下文路径完成的(http://localhost:8080/myapp/app/rest),但总是有一个404错误。我已经将该文件重新命名为ROOT。战争,但行为是一样的:
I saw that an issue was closed with the webapp context, so it should be ok ? https://github.com/jhipster/generator-jhipster/issues/235 When I deploy the same application Tomcat, it's ok...
我看到一个问题被webapp上下文关闭了,所以应该没问题吧?当我部署同一个应用程序Tomcat时,可以……
I think my issue is linked with servlet registring. For instance /api-docs for swagger-ui is not available also.
我认为我的问题与servlet registring有关。例如,对于大款用户界面的api文档也没有。
Any idea, please ?
任何想法吗?
1 个解决方案
#1
2
The issue is linked with Spring Dispatcher Servlet that is mapped with /
. It's ok with Tomcat but not with JBoss AS. So I added a mapping with /*
to allow deployment in JBoss AS. This method could be added in WebConfigurer :
这个问题与映射的Spring Dispatcher Servlet有关。在Tomcat上可以,但不能和JBoss一样。因此,我添加了一个与/*的映射,以允许在JBoss中部署。这种方法可以在WebConfigurer中添加:
public void onStartup(ServletContext servletContext) throws ServletException {
[...]
initDispatcherServlet(servletContext, disps);
[...]
}
/**
* Initializes Spring Dispatch Servlet to allow deployment in JBoss
*/
private void initDispatcherServlet(ServletContext servletContext, EnumSet<DispatcherType> disps) {
// Using listener to be able to get the Dispatcher Servlet not yet initialized
servletContext.addListener(new ServletContextListener() {
@Override
public void contextInitialized(ServletContextEvent event) {
try {
Map<String, ? extends ServletRegistration> servlets=null;
servlets = event.getServletContext().getServletRegistrations();
Set<String> keys = servlets.keySet();
log.debug("Registred servlets : "+keys);
ServletRegistration dspSrvlt = servlets.get("dispatcherServlet");
if(dspSrvlt != null) {
Collection<String> maps = dspSrvlt.getMappings();
log.debug("Dispatcher servlet mapping size : "+maps.toArray().length);
log.debug("Servlet dispatcher mapping : "+maps);
if( !maps.contains("/*") ) {
log.debug("Adding /* for Spring Dispatcher servlet");
servlets.get("dispatcherServlet").addMapping("/*");
}
} else {
log.warn("Unable to change the Servlet Request dispatcher mapping to allow deployment with JBoss");
}
} catch (Exception e) {
log.warn("Unable to change the Servlet Context to allow deployment with JBoss");
}
}
@Override
public void contextDestroyed(ServletContextEvent arg0) {
}
});
}
#1
2
The issue is linked with Spring Dispatcher Servlet that is mapped with /
. It's ok with Tomcat but not with JBoss AS. So I added a mapping with /*
to allow deployment in JBoss AS. This method could be added in WebConfigurer :
这个问题与映射的Spring Dispatcher Servlet有关。在Tomcat上可以,但不能和JBoss一样。因此,我添加了一个与/*的映射,以允许在JBoss中部署。这种方法可以在WebConfigurer中添加:
public void onStartup(ServletContext servletContext) throws ServletException {
[...]
initDispatcherServlet(servletContext, disps);
[...]
}
/**
* Initializes Spring Dispatch Servlet to allow deployment in JBoss
*/
private void initDispatcherServlet(ServletContext servletContext, EnumSet<DispatcherType> disps) {
// Using listener to be able to get the Dispatcher Servlet not yet initialized
servletContext.addListener(new ServletContextListener() {
@Override
public void contextInitialized(ServletContextEvent event) {
try {
Map<String, ? extends ServletRegistration> servlets=null;
servlets = event.getServletContext().getServletRegistrations();
Set<String> keys = servlets.keySet();
log.debug("Registred servlets : "+keys);
ServletRegistration dspSrvlt = servlets.get("dispatcherServlet");
if(dspSrvlt != null) {
Collection<String> maps = dspSrvlt.getMappings();
log.debug("Dispatcher servlet mapping size : "+maps.toArray().length);
log.debug("Servlet dispatcher mapping : "+maps);
if( !maps.contains("/*") ) {
log.debug("Adding /* for Spring Dispatcher servlet");
servlets.get("dispatcherServlet").addMapping("/*");
}
} else {
log.warn("Unable to change the Servlet Request dispatcher mapping to allow deployment with JBoss");
}
} catch (Exception e) {
log.warn("Unable to change the Servlet Context to allow deployment with JBoss");
}
}
@Override
public void contextDestroyed(ServletContextEvent arg0) {
}
});
}