我試圖實現Spring MVC應用程序,將它部署在JBoss上並能夠通過我的瀏覽器調用它。未找到Spring MVC完整代碼請求映射
我的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文件,我的瀏覽器可以查找和讀取本地主機:8080/CLC 但是,當我試圖進入一個映射的路線,像本地主機:8080/CLC /測試 我收到了404個
什麼可能是根任何提示對我的問題?
另外,如果不知道它的相關性,但春天的版本是4.3.10釋放,和JBoss被廣泛
更新: 所以,我降級春季版本4.3.7釋放和現在一切工作正常,關於爲什麼?我也證明是行家降級之前,捆綁每一個部件具有相同的彈簧版本
能否請您試試這個:dispatcher.addMapping(「/ *」);只是爲了確保Dispatcher Servlet能夠處理您的所有請求。 –
'localhost:8080/CLC/test?name = test'怎麼辦? – StanislavL
@StanislavL假設參數與請求本身沒有任何關係,變量將變爲空。還是我錯了?無論如何,謝謝你,我試過了。但沒有好處:( –