Aula: 01
Problema: Quando subo o servidor estou com o erro "No Spring WebApplicationInitializer types detected on classpath" no console, por causa deste problema acredito que o spring não esteja atendendo as requisições, pois ao acessar localhost:8080/casadocodigo recebo erro 404.
Obs: Revisei todo o processo da video aula para ver se não estava deixando passar algum passo importante mas acredito que esteja tudo correto.
ServletSpringMVC.java
package br.com.casadocodigo.loja.conf;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class ServletSpringMVC extends AbstractAnnotationConfigDispatcherServletInitializer{
@Nullable
@Override
protected Class<?>[] getRootConfigClasses() {
return null;
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[] {AppWebConfiguration.class} ;
}
@Override
protected String[] getServletMappings() {
return new String[] {"/"};
}
}
AppWebConfiguration.java
package br.com.casadocodigo.loja.conf;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@EnableWebMvc
@Configuration
@ComponentScan(basePackageClasses={HomeController.class})
public class AppWebConfiguration {
@Bean
public InternalResourceViewResolver internalResourceViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
return resolver;
}
}
HomeController.java
package br.com.casadocodigo.loja.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HomeController {
@RequestMapping("/")
public String index() {
System.out.println("[HomeController:index] Start");
return "home";
}
}
home.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Livros de Java, Android, iPhone, PHP, Ruby e muito mais - Casa do Código</title>
</head>
<body>
<h1>Casa do Código</h1>
<table>
<tr>
<td>Java 8 Prático</td>
<td>Certificação OCJP</td>
</tr>
<tr>
<td>TDD na Prática - Java</td>
<td>Google Android</td>
</tr>
</table>
</body>
</html>