SpringMVC Jetty - Error 404

0

Witam!
Uczę się Springa i przerabiam właśnie kurs o MVC w Springu. Utworzyłam pierwszy/startowy projekt zgodnie z instrukcjami prowadzącego i go uruchomiłam. Niestety kiedy próbuję wejść na localhost:8080/carservice/{cokolwiek} dostaję Error 404 (Problem accessing /carservice/s. Reason: Not Found) i nie rozumiem dlaczego.

CarServiceWebApplicationConfigurer.java

package pl.videopoint.carservice;

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

public class CarServiceWebApplicationConfigurer extends AbstractAnnotationConfigDispatcherServletInitializer {

	@Override
	protected Class<?>[] getRootConfigClasses() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected Class<?>[] getServletConfigClasses() {
		// TODO Auto-generated method stub
		return new Class[] {CarServiceWebConfiguration.class};
	}

	@Override
	protected String[] getServletMappings() {
		// TODO Auto-generated method stub
		return new String[] {"/"};
	}

}

CarServiceWebConfiguration.java

package pl.videopoint.carservice;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan("pl.videopoint.carservice")
public class CarServiceWebConfiguration {

}

IssuesController.java

package pl.videopoint.carservice.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class IssuesController {
	
	@RequestMapping("/**")
	@ResponseBody
	public String test() {
		
	return "Hello";
	}

}

pom.xml

<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>
  <groupId>pl.videopoint</groupId>
  <artifactId>carservice</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <name>carservice</name>
  <description>Obsługa warsztatu samochowdowego</description>
  <build>
  <plugins>
  <plugin>
   <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
   <version>3.2.2</version>
  
           <configuration>
          <webappDirectory>src/main/webapp</webappDirectory>
        </configuration>

  </plugin>
  </plugins>
  </build>
  <dependencies>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-webmvc</artifactId>
  		<version>5.1.4.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>javax.servlet</groupId>
  		<artifactId>javax.servlet-api</artifactId>
  		<version>4.0.1</version>
  		<scope>provided</scope>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-context</artifactId>
  		<version>5.1.4.RELEASE</version>
  	</dependency>
  </dependencies>
</project>
0

A pokaż startup log. Spring loguje przecież jakie kontrolery znalazł i pod jakimi URLami je wystawił. Czemu uważasz ze to się zdeployuje pod /carservice a nie w roocie?

0
>   
2019-02-09 01:22:06.372:INFO::main: Logging initialized @410ms to org.eclipse.jetty.util.log.StdErrLog
   Configuration: C:\Users\user\AppData\Local\Temp\eclipseJettyPlugin.config.carservice.xml
         Version: 9.4.14.v20181114
         Context: /carservice
            Port: 8080
       Classpath: C:/Users/user/.m2/repository/org/springframework/spring-aop/5.1.4.RELEASE/spring-aop-5.1.4.RELEASE.jar
                  C:/Users/user/.m2/repository/org/springframework/spring-beans/5.1.4.RELEASE/spring-beans-5.1.4.RELEASE.jar
                  C:/Users/user/.m2/repository/org/springframework/spring-context/5.1.4.RELEASE/spring-context-5.1.4.RELEASE.jar
                  C:/Users/user/.m2/repository/org/springframework/spring-core/5.1.4.RELEASE/spring-core-5.1.4.RELEASE.jar
                  C:/Users/user/.m2/repository/org/springframework/spring-expression/5.1.4.RELEASE/spring-expression-5.1.4.RELEASE.jar
                  C:/Users/user/.m2/repository/org/springframework/spring-jcl/5.1.4.RELEASE/spring-jcl-5.1.4.RELEASE.jar
                  C:/Users/user/.m2/repository/org/springframework/spring-web/5.1.4.RELEASE/spring-web-5.1.4.RELEASE.jar
                  C:/Users/user/.m2/repository/org/springframework/spring-webmvc/5.1.4.RELEASE/spring-webmvc-5.1.4.RELEASE.jar
2019-02-09 01:22:07.583:INFO:oejs.Server:main: jetty-9.4.14.v20181114; built: 2018-11-14T21:20:31.478Z; git: c4550056e785fb5665914545889f21dc136ad9e6; jvm 11.0.1+13-LTS
2019-02-09 01:22:09.146:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=202ms
2019-02-09 01:22:09.163:INFO:oejshC.carservice:main: No Spring WebApplicationInitializer types detected on classpath
2019-02-09 01:22:09.264:INFO:oejs.session:main: DefaultSessionIdManager workerName=node0
2019-02-09 01:22:09.264:INFO:oejs.session:main: No SessionScavenger set, using defaults
2019-02-09 01:22:09.268:INFO:oejs.session:main: node0 Scavenging every 600000ms
2019-02-09 01:22:09.272:WARN:oejs.SecurityHandler:main: [email protected]@2b76ff4e{/carservice,file:///C:/Users/user/eclipse-workspace/eclipse-18/carservice/src/main/webapp/,STARTING}{C:\Users\user\eclipse-workspace\eclipse-18\carservice\src\main\webapp} has uncovered http methods for path: /
2019-02-09 01:22:09.396:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@2b76ff4e{/carservice,file:///C:/Users/user/eclipse-workspace/eclipse-18/carservice/src/main/webapp/,AVAILABLE}{C:\Users\user\eclipse-workspace\eclipse-18\carservice\src\main\webapp}
2019-02-09 01:22:09.438:INFO:oejs.AbstractConnector:main: Started ServerConnector@5629510{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2019-02-09 01:22:09.439:INFO:oejs.Server:main: Started @3493ms
-----------------------------------------------
Jetty startup finished in 3,3 s.
Used memory: 5,2 MB of 48,0 MB (8,0 GB maximum)
Console available: type "help".
-----------------------------------------------
0

Tak na oko to Spring w ogóle tego nie wykrył i nic nie przeskanował. Zamiast tego CarServiceWebApplicationConfigurer dorzuć SpringBoota do zalezności i zrób autokonfiguracje, bo przypuszczam że ten twój startup konfig dla servletu springowego jest rypnięty.

0

Spróbuj dodać @EnableWebMvc do konfiguracji.

1 użytkowników online, w tym zalogowanych: 0, gości: 1