我正在尝试实现一个Spring mvc应用程序,将其部署在JBoss上,并能够通过我的浏览器调用它。
我的WebConfig:
package com.heatmanofurioso.concertlivecheck.webapp;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
public class WebConfig implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
//Defining web xml
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(SpringApplicationConfig.class);
rootContext.setServletContext(servletContext);
//Registering servlet
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(rootContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
servletContext.addListener(new ContextLoaderListener(rootContext));
}
}
的JBoss-web.xml中
<?xml version="1.0" encoding="UTF-8" ?>
<jboss-web>
<context-root>CLC</context-root>
</jboss-web>
登录控制器
package com.heatmanofurioso.concertlivecheck.plugin.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class LoginController {
@RequestMapping(value = "/test", method = RequestMethod.GET)
public String greeting5(@RequestParam(value = "name", defaultValue = "World1") String name) {
return "Test" + name;
}
}
SpringApplicationConfig
package com.heatmanofurioso.concertlivecheck.webapp;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@EnableWebMvc
@Configuration
@ComponentScan(basePackages = {
"com.heatmanofurioso.concertlivecheck",
"com.heatmanofurioso.concertlivecheck.plugin"})
public class SpringApplicationConfig extends WebMvcConfigurerAdapter {
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
我的春季版本都是最新的4.x版本,并在我的主要pom上宣布 我的webapp pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<artifactId>webapp</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>com.heatmanofurioso.concertlivecheck</groupId>
<artifactId>ConcertLiveCheck</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<!--Project modules-->
<dependency>
<groupId>com.heatmanofurioso.concertlivecheck</groupId>
<artifactId>utils</artifactId>
</dependency>
<dependency>
<groupId>com.heatmanofurioso.concertlivecheck</groupId>
<artifactId>database</artifactId>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.heatmanofurioso.concertlivecheck</groupId>
<artifactId>service</artifactId>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.heatmanofurioso.concertlivecheck</groupId>
<artifactId>plugin</artifactId>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warName>${parent.artifactId}</warName>
<outputDirectory>${project.build.directory}/../../../../../deployments/</outputDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>sources</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<properties>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
</project>
我有一个示例jsp文件,我的浏览器可以在localhost:8080 / CLC上找到并读取 但是,当我尝试进入映射路由时,如localhost:8080 / CLC / test 我得到了404
关于什么可能是我的问题根源的任何提示?
另外,不确定它是否相关,但是Spring版本是4.3.10版本,而JBoss是Wildly
更新: 所以,我将spring版本降级到4.3.7版本,现在一切正常,有什么想法吗?我还证明,在降级maven之前,每个组件都使用相同的弹簧版本进行捆绑
答案 0 :(得分:0)
您不需要公开应用程序名称,只需为以下内容发出GET请求:
http://localhost:8080/test
如果您想在网址中再添加一个级别,可以执行以下操作:
@RequestMapping(value = "CLC/test", method = RequestMethod.GET)
public String greeting5(@RequestParam(value = "name", defaultValue = "World1") String name) {
return "Test" + name;
}
答案 1 :(得分:0)
最新的弹簧安全使用弹簧芯4.3.7,我使用弹簧芯4.3.10。
这些图书馆在我的罐子里发生了冲突。
我将我的弹簧核心降级到4.3.7并且一切正常