Spring Boot error 404

1

Hello, I'm studying Spring Mvc and Spring Boot and I came across the following problem that I have not been able to identify yet. After running my main method I get the following message.

Whitelabel Error Page

This application has no explicit mapping for / error, so you are seeing ** this as a fallback. Tue Jul 19 21:22:43 BRT 2016 There was an unexpected error (type = Not Found, status = 404). No message available

Controller

@Controller
public class HomeController {

    @RequestMapping(value="/login", method=RequestMethod.GET)
    public String redirect() {
        return "login/login";
    }
}

Main method

@SpringBootApplication()
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

Configuration

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.gervasios.rsw")
public class ApplicationConfiguration extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
    }

    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setViewClass(JstlView.class);
        viewResolver.setPrefix("/WEB-INF/pages/");
        viewResolver.setSuffix(".jsp");
        registry.viewResolver(viewResolver);
    }
}

POM

<!-- Spring BOOT-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.5.RELEASE</version>
    </parent>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <url>http://repo.spring.io/snapshot</url>
            <snapshots><enabled>true</enabled></snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <url>http://repo.spring.io/milestone</url>
        </repository>
    </repositories>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <spring.version>4.2.5.RELEASE</spring.version>          
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>

        <!-- Javax - Jsf -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

LOG localhost: 8080 / restauranteWeb

  .   ____          _            __ _ _
 /\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _' | \ \ \ \
 \/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.3.5.RELEASE)

2016-07-19 21:22:34.153  INFO 4480 --- [           main] com.gervasios.rsw.run.Application        : Starting Application on Helio-PC with PID 4480 (C:\Users\Helio\git\restauranteWeb\restauranteWeb\target\classes started by Helio in C:\Users\Helio\git\restauranteWeb\restauranteWeb)
2016-07-19 21:22:34.160  INFO 4480 --- [           main] com.gervasios.rsw.run.Application        : No active profile set, falling back to default profiles: default
2016-07-19 21:22:34.251  INFO 4480 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@1f32bf7: startup date [Tue Jul 19 21:22:34 BRT 2016]; root of context hierarchy
2016-07-19 21:22:36.222  INFO 4480 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$c19cd918] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-07-19 21:22:36.976  INFO 4480 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-07-19 21:22:36.997  INFO 4480 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2016-07-19 21:22:36.999  INFO 4480 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.0.33
2016-07-19 21:22:37.169  INFO 4480 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2016-07-19 21:22:37.169  INFO 4480 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2920 ms
2016-07-19 21:22:37.606  INFO 4480 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
2016-07-19 21:22:37.611  INFO 4480 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-07-19 21:22:37.611  INFO 4480 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-07-19 21:22:37.611  INFO 4480 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-07-19 21:22:37.611  INFO 4480 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'requestContextFilter' to: [/*]
2016-07-19 21:22:38.370  INFO 4480 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2016-07-19 21:22:38.383  INFO 4480 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2016-07-19 21:22:38.483  INFO 4480 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {4.3.11.Final}
2016-07-19 21:22:38.486  INFO 4480 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2016-07-19 21:22:38.488  INFO 4480 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2016-07-19 21:22:38.732  INFO 4480 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2016-07-19 21:22:38.806  INFO 4480 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2016-07-19 21:22:38.872  INFO 4480 --- [           main] o.h.h.i.ast.ASTQueryTranslatorFactory    : HHH000397: Using ASTQueryTranslatorFactory
2016-07-19 21:22:39.332  INFO 4480 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@1f32bf7: startup date [Tue Jul 19 21:22:34 BRT 2016]; root of context hierarchy
2016-07-19 21:22:39.423  INFO 4480 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-07-19 21:22:39.424  INFO 4480 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2016-07-19 21:22:39.462  INFO 4480 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-07-19 21:22:39.463  INFO 4480 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-07-19 21:22:39.523  INFO 4480 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-07-19 21:22:39.796  INFO 4480 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2016-07-19 21:22:39.906  INFO 4480 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-07-19 21:22:39.911  INFO 4480 --- [           main] com.gervasios.rsw.run.Application        : Started Application in 6.145 seconds (JVM running for 6.645)
2016-07-19 21:22:43.072  INFO 4480 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2016-07-19 21:22:43.072  INFO 4480 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2016-07-19 21:22:43.094  INFO 4480 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 22 ms

Index.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<h1>Por Favor Aguarde...</h1>
<c:redirect url="/login"/>
    
asked by anonymous 20.07.2016 / 02:32

1 answer

1

Because of the error that was displayed (404), you are probably accessing a URL that is not mapped on your server. I copied your class and ran it normally in my application, accessing localhost: 8080 / login (url that was mapped in @RequestMaping of your controller).

By which address are you trying to access your view?

To access localhost: 8080 / restauranteWeb you will need to create a controller that will respond to this URL, otherwise you will not be able to access.

Try to create something like:

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value="/restauranteWeb")
public class RestauranteWebController {

 @RequestMapping(method=RequestMethod.GET)
    public ModelAndView redirect() {
        ModelAndView mv = new ModelAndView("Index.jsp");
        return mv;
    }

}

    
21.07.2016 / 16:44