11
respostas

Não esta encontrando a pagina404

Criei o projeto com o Jboss Developer Studio, porém ele nao encontra o home.jsp criei o diretorio tudo certo mas da o erro 404

colo quei alguns print para verificar mas não apareceu no console

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 toko.tt.controller.HomeController;

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

    @Bean
    public InternalResourceViewResolver internalResourceViewResolver(){
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        System.out.println("ta passando por aqui");
        resolver.setPrefix("WEB-INF/views/");
        resolver.setSuffix(".jsp");
        return resolver;

    }
11 respostas

Olá Daniel, blz? Posta ai pra gente sua classe HomeController e a outra classe que extends AbstractAnnotationConfigDispatcherServletInitializer.

package toko.da.controller;

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

@Controller
public class HomeController {

    @RequestMapping("/home")
    public String home(){
        System.out.println("Home controller home");
        return "home";
    }
}
package toko.da;

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

public class ServeletSpring 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[]{AppWebConfig.class};
    }

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

}

Eu acho que estou fazendo algo errado na hora de criar um projeto, estou usando o JBoss developer file->new Maven project -> nesse momento pede para selecionar o archetype e eu estou ussando o spring-boot-black-archetype

com o código acima aconteceu esse erro "Circular view path [home]: would dispatch back to the current handler URL [/home] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)"

Daniel, qual a URL você está acessando?

Disponibiliza seu projeto lá no GitHub pra eu fazer um teste aqui no meu pc.

Daniel Massanori, no

resolver.setPrefix("WEB-INF/views/");

da sua classe AppWebConfig está faltando um / antes de WEB-INF.

Olá Boa Noite, Estou com o mesmo problema:

@Controller
public class HomeController {
    @RequestMapping("/home")
    public String index(){
        System.out.println("Exibindo a home da CDC");
        return "teste";

    }
}

**************************************************
public class ServletSpringMVC extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return null;
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[] {AppWebConfiguration.class};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

}
**************************************************************

@EnableWebMvc
@ComponentScan(basePackageClasses = { HomeController.class })
public class AppWebConfiguration {
    @Bean
    public InternalResourceViewResolver internalResourceViewResolve() {
        InternalResourceViewResolver resolve = new InternalResourceViewResolver();
        resolve.setPrefix("/WEB-INF/views/");
        resolve.setSuffix(".jsp");
        return resolve;
    }
}

Obs: se eu alterar as paginas para .xhtml vai funcionar também??

Cleiton, aparentemente tá tudo correto com as suas configurações.

Você não tá errando a url para acessar sua rota no browser?

Lembre-se, uma rota é acessada assim:

http://localhost:8080/(nome da sua aplicação)/(rota do seu controller)

ou seja, se o nome da aplicação (contexto) for "loja" e você tem uma rota chamada "/home", então sua url ficará assim:

http://localhost:8080/loja/home

Outro erro que pode ser é, vc tem uma pagina chamada teste.jsp em /WEB-INF/views/?

Olá João Blza, seguinte, estou usando assim:

http://localhost:8080/springalura/home

e eu tenho uma página teste.jsp. Já tentei usar teste.xhtml e alterar o resolve.setSuffix para ".xhtml ", mas também não funcionou. Estou usando o tomcat 9. Também tentei rodar com o wildfly 10 mas deu o mesmo erro....

Hum, vc pode postar o log que aparece no seu console?

No Wildfly

15:24:58,042 INFO  [org.jboss.modules] (main) JBoss Modules version 1.5.2.Final
15:25:10,157 INFO  [org.jboss.msc] (main) JBoss MSC version 1.2.6.Final
15:25:11,050 INFO  [org.jboss.as] (MSC service thread 1-7) WFLYSRV0049: WildFly Full 10.1.0.Final (WildFly Core 2.2.0.Final) starting
15:26:04,347 INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) WFLYDS0004: Found springalura.war in deployment directory. To trigger deployment create a file called springalura.war.dodeploy
15:26:04,575 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creating http management service using socket-binding (management-http)
15:26:05,218 INFO  [org.xnio] (MSC service thread 1-2) XNIO version 3.4.0.Final
15:26:05,237 INFO  [org.xnio.nio] (MSC service thread 1-2) XNIO NIO Implementation Version 3.4.0.Final
15:26:06,741 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 63) WFLYCLINF0001: Activating Infinispan subsystem.
15:26:06,768 WARN  [org.jboss.as.txn] (ServerService Thread Pool -- 79) WFLYTX0013: Node identifier property is set to the default value. Please make sure it is unique.
15:26:06,838 INFO  [org.jboss.as.security] (ServerService Thread Pool -- 78) WFLYSEC0002: Activating Security Subsystem
15:26:06,840 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 71) WFLYNAM0001: Activating Naming Subsystem
15:26:06,857 INFO  [org.jboss.as.jsf] (ServerService Thread Pool -- 69) WFLYJSF0007: Activated the following JSF Implementations: [main]
15:26:06,952 INFO  [org.jboss.as.security] (MSC service thread 1-7) WFLYSEC0001: Current PicketBox version=4.9.6.Final
15:26:06,991 INFO  [org.jboss.as.webservices] (ServerService Thread Pool -- 81) WFLYWS0002: Activating WebServices Extension
15:26:07,011 INFO  [org.wildfly.extension.io] (ServerService Thread Pool -- 62) WFLYIO001: Worker 'default' has auto-configured to 8 core threads with 64 task threads based on your 4 available processors
15:26:07,154 INFO  [org.jboss.as.connector] (MSC service thread 1-6) WFLYJCA0009: Starting JCA Subsystem (WildFly/IronJacamar 1.3.4.Final)
15:26:08,743 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-5) WFLYUT0003: Undertow 1.4.0.Final starting
15:26:11,006 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 80) WFLYUT0014: Creating file handler for path 'E:\Development\JavaWeb\wildfly-10.1.0.Final/welcome-content' with options [directory-listing: 'false', follow-symlink: 'false', case-sensitive: 'true', safe-symlink-paths: '[]']
15:26:11,339 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 58) WFLYJCA0004: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
15:26:11,346 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) WFLYJCA0018: Started Driver service with driver-name = h2
15:26:15,537 INFO  [org.jboss.as.naming] (MSC service thread 1-4) WFLYNAM0003: Starting Naming Service
15:26:15,538 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-8) WFLYMAIL0001: Bound mail session [java:jboss/mail/Default]
15:26:16,214 INFO  [org.jboss.remoting] (MSC service thread 1-2) JBoss Remoting version 4.0.21.Final
15:26:16,337 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-4) WFLYUT0012: Started server default-server.
15:26:16,425 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-4) WFLYUT0018: Host default-host starting
15:26:17,081 INFO  [org.jboss.as.ejb3] (MSC service thread 1-5) WFLYEJB0481: Strict pool slsb-strict-max-pool is using a max instance size of 64 (per class), which is derived from thread worker pool sizing.
15:26:17,082 INFO  [org.jboss.as.ejb3] (MSC service thread 1-1) WFLYEJB0482: Strict pool mdb-strict-max-pool is using a max instance size of 16 (per class), which is derived from the number of CPUs on this host.
15:26:17,980 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0006: Undertow HTTP listener default listening on 127.0.0.1:8080
15:26:18,906 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) WFLYJCA0001: Bound data source [java:jboss/datasources/ExampleDS]
15:26:20,041 WARN  [org.jboss.as.domain.management.security] (MSC service thread 1-5) WFLYDM0111: Keystore E:\Development\JavaWeb\wildfly-10.1.0.Final\standalone\configuration\application.keystore not found, it will be auto generated on first use with a self signed certificate for host localhost
15:26:20,319 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-1) WFLYDS0013: Started FileSystemDeploymentService for directory E:\Development\JavaWeb\wildfly-10.1.0.Final\standalone\deployments
15:26:20,330 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-8) WFLYSRV0027: Starting deployment of "springalura.war" (runtime-name: "springalura.war")
15:26:23,926 INFO  [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-6) ISPN000128: Infinispan version: Infinispan 'Chakra' 8.2.4.Final
15:26:24,996 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 90) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
15:26:25,002 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 90) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
15:26:25,029 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 86) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
15:26:25,034 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 86) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
15:26:25,048 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 84) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
15:26:25,052 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 84) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
15:26:30,146 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-1) WFLYUT0006: Undertow HTTPS listener https listening on 127.0.0.1:8443
15:26:39,851 INFO  [org.jboss.ws.common.management] (MSC service thread 1-8) JBWS022052: Starting JBossWS 5.1.5.Final (Apache CXF 3.1.6) 
15:26:49,762 WARN  [org.jboss.as.ee] (MSC service thread 1-8) WFLYEE0007: Not installing optional component org.springframework.http.server.ServletServerHttpAsyncRequestControl due to an exception (enable DEBUG log level to see the cause)
15:26:49,765 WARN  [org.jboss.as.ee] (MSC service thread 1-8) WFLYEE0007: Not installing optional component org.springframework.web.context.request.async.StandardServletAsyncWebRequest due to an exception (enable DEBUG log level to see the cause)
15:26:56,062 INFO  [io.undertow.servlet] (ServerService Thread Pool -- 108) No Spring WebApplicationInitializer types detected on classpath
15:26:57,839 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 108) Inicializando Mojarra 2.2.13.SP1 20160303-1204 para o contexto '/springalura'
15:27:04,778 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 108) WFLYUT0021: Registered web context: /springalura
15:27:05,350 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 59) WFLYSRV0010: Deployed "springalura.war" (runtime-name : "springalura.war")
15:27:06,216 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
15:27:06,219 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
15:27:06,220 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 10.1.0.Final (WildFly Core 2.2.0.Final) started in 140518ms - Started 813 of 1063 services (404 services are lazy, passive or on-demand)

E no Tomcat 9

mar 05, 2017 3:36:13 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
ADVERTÊNCIA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:springalura' did not find a matching property.
mar 05, 2017 3:36:13 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Server version:        Apache Tomcat/9.0.0.M17
mar 05, 2017 3:36:13 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Server built:          Jan 10 2017 20:59:20 UTC
mar 05, 2017 3:36:13 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Server number:         9.0.0.0
mar 05, 2017 3:36:13 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: OS Name:               Windows 10
mar 05, 2017 3:36:13 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: OS Version:            10.0
mar 05, 2017 3:36:13 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Architecture:          amd64
mar 05, 2017 3:36:13 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Java Home:             C:\Program Files\Java\jdk1.8.0_121\jre
mar 05, 2017 3:36:13 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: JVM Version:           1.8.0_121-b13
mar 05, 2017 3:36:13 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: JVM Vendor:            Oracle Corporation
mar 05, 2017 3:36:13 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: CATALINA_BASE:         E:\Development\JavaWeb\Eclipse-Projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
mar 05, 2017 3:36:13 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: CATALINA_HOME:         E:\Development\JavaWeb\Apache Tomcat\apache-tomcat-9.0.0.M17
mar 05, 2017 3:36:13 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dcatalina.base=E:\Development\JavaWeb\Eclipse-Projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
mar 05, 2017 3:36:13 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dcatalina.home=E:\Development\JavaWeb\Apache Tomcat\apache-tomcat-9.0.0.M17
mar 05, 2017 3:36:13 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dwtp.deploy=E:\Development\JavaWeb\Eclipse-Projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
mar 05, 2017 3:36:13 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Djava.endorsed.dirs=E:\Development\JavaWeb\Apache Tomcat\apache-tomcat-9.0.0.M17\endorsed
mar 05, 2017 3:36:13 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dfile.encoding=Cp1252
mar 05, 2017 3:36:13 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFORMAÇÕES: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.8.0_121\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre1.8.0_121/bin/server;C:/Program Files/Java/jre1.8.0_121/bin;C:/Program Files/Java/jre1.8.0_121/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Java\jre1.8.0_121\bin;C:\Program Files\MySQL\MySQL Server 5.7\bin;C:\Users\Cleiton Carlos\AppData\Local\Microsoft\WindowsApps;;E:\Development\JavaWeb\eclipse;;.
mar 05, 2017 3:36:15 PM org.apache.coyote.AbstractProtocol init
INFORMAÇÕES: Initializing ProtocolHandler ["http-nio-8080"]
mar 05, 2017 3:36:16 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMAÇÕES: Using a shared selector for servlet write/read
mar 05, 2017 3:36:16 PM org.apache.coyote.AbstractProtocol init
INFORMAÇÕES: Initializing ProtocolHandler ["ajp-nio-8009"]
mar 05, 2017 3:36:16 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMAÇÕES: Using a shared selector for servlet write/read
mar 05, 2017 3:36:16 PM org.apache.catalina.startup.Catalina load
INFORMAÇÕES: Initialization processed in 6105 ms
mar 05, 2017 3:36:16 PM org.apache.catalina.core.StandardService startInternal
INFORMAÇÕES: Starting service Catalina
mar 05, 2017 3:36:16 PM org.apache.catalina.core.StandardEngine startInternal
INFORMAÇÕES: Starting Servlet Engine: Apache Tomcat/9.0.0.M17
mar 05, 2017 3:36:23 PM org.apache.jasper.servlet.TldScanner scanJars
INFORMAÇÕES: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
mar 05, 2017 3:36:23 PM org.apache.catalina.core.ApplicationContext log
INFORMAÇÕES: No Spring WebApplicationInitializer types detected on classpath
mar 05, 2017 3:36:24 PM org.apache.coyote.AbstractProtocol start
INFORMAÇÕES: Starting ProtocolHandler [http-nio-8080]
mar 05, 2017 3:36:24 PM org.apache.coyote.AbstractProtocol start
INFORMAÇÕES: Starting ProtocolHandler [ajp-nio-8009]
mar 05, 2017 3:36:24 PM org.apache.catalina.startup.Catalina start
INFORMAÇÕES: Server startup in 7491 ms

Pessoal, eu também estava com o mesmo problema, vou citar abaixo os trechos onde devem tomar atenção, pois foi onde errei:

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

        return resolver;
    }
  • Não esqueçam do @Bean, se estiver retornando o erro: "Could not resolve view with name 'htmlviews/index.html' in servlet with name 'dispatcher' .." o problema provavelmente é esse.
  • Atentem ao minuto 7:34 de vídeo, tentem fazer exatamente igual o instrutor, aqui visualmente estava igual mas não estava pegando o setPrefix e o setSuffix corretos, utilizem o ctrl+space.
  • Outro ponto no mesmo minuto, é quando ele dá CTRL+1, eu substitui pra resolver na mão, por isso não pegava a classe correta, aparentemente estava igual, só que não funcionava (inclusive um amigo acima escreveu "resolve", o problema dele é exatamente o que tive). Espero ter ajudado.

Estou com o mesmo problema, esta tudo correto e não funciona, algum professor pode nos ajudar aqui por favor!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software