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>
- spring_mvc2.PNG (158 KB) - ściągnięć: 70
- spring_mvc1.PNG (44 KB) - ściągnięć: 53