2
respostas

Erro 404

Ao iniciar o servidor, sempre esta sendo redirecionado para a pagina 404, já conferi o codigo e a estrutura da aplicação, mas infelizmente sempre esta dando este erro. saida do console

GRAVE: Error during ServletContainerInitializer processing
javax.servlet.ServletException: Failed to instantiate WebApplicationInitializer class
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:158)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5630)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1700)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1690)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:155)
    ... 8 more
Caused by: java.lang.NoClassDefFoundError: org/apache/log4j/Level
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121)
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:268)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:241)
    at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:156)
    at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:272)
    at org.springframework.web.context.AbstractContextLoaderInitializer.<init>(AbstractContextLoaderInitializer.java:45)
    at org.springframework.web.servlet.support.AbstractDispatcherServletInitializer.<init>(AbstractDispatcherServletInitializer.java:53)
    at org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer.<init>(AbstractAnnotationConfigDispatcherServletInitializer.java:44)
    at br.com.casadocodigo.loja.conf.ServletSpringMVC.<init>(ServletSpringMVC.java:5)
    ... 13 more
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Level
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1907)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1750)
    ... 24 more

fev 22, 2018 11:12:04 AM org.apache.catalina.core.StandardContext startInternal
GRAVE: Context [/casadocodigo] startup failed due to previous errors
fev 22, 2018 11:12:04 AM org.apache.coyote.AbstractProtocol start
INFORMAÇÕES: Starting ProtocolHandler ["http-bio-8080"]
fev 22, 2018 11:12:04 AM org.apache.coyote.AbstractProtocol start
INFORMAÇÕES: Starting ProtocolHandler ["ajp-bio-8009"]
fev 22, 2018 11:12:04 AM org.apache.catalina.startup.Catalina start
INFORMAÇÕES: Server startup in 9006 ms

Classe ServletSpringMvc

package br.com.casadocodigo.loja.conf;

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

public class ServletSpringMVC extends AbstractAnnotationConfigDispatcherServletInitializer {

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

    //configure class with we are working
    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[] {AppWebConfiguration.class};
    }

    //mapping urls to redirect to "/URL"
    @Override
    protected String[] getServletMappings() {
        return new String[] {"/"};
    }

}
Classe AppWebConfiguration.java

package br.com.casadocodigo.loja.conf;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import br.com.casadocodigo.loja.controllers.HomeController;

@EnableWebMvc
//search in project package with contains our Controller
@ComponentScan(basePackageClasses={HomeController.class})
public class AppWebConfiguration {

    @Bean
    public InternalResourceViewResolver internalResourceViewResolver() {
    InternalResourceViewResolver resolver = new InternalResourceViewResolver();
    resolver.setPrefix("/WEB-INF/views/");
    resolver;
}
}
2 respostas

Fala ai Welson, tudo bem ?

Pelo erro parece que você não colocou algum dependencia, de repente na hora de baixar ele não conseguiu e acabou a corrompendo.

Acho que vale a pena você apagar a pasta .m2 que fica no diretorio do usuario.

Fala Matheus, então cara fiz o procedimento que você informou, mas não funcionou novamente. realizei o procedimento que consta neste material 3 vezes, e sempre obtenho o mesmo resultado.

https://cursos.alura.com.br/course/spring-mvc-1-criando-aplicacoes-web/task/11383

@EnableWebMvc
@ComponentScan(basePackageClasses={HomeController.class})
public class AppWebConfiguration {

}

após esse trecho, ao apagar a pagina index.html era pra ser obtido uma resposta diferente de 404.