5
respostas

Timeout TomCat, fica parado no INFO: Initializing Spring FrameworkServlet 'dispatcher'

Olá, prezados! Não consigo inicializar o Tomcat. Sempre quando tento iniciar , no console da Timeout, ja aumentai o timeout para um tempo de 300seg, mas ainda sim não inicia:

Obs: nos primeiros exercícios sem utilizar o Hibernate funcionava.

Sep 21, 2016 10:38:52 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:casadocodigo' did not find a matching property.
Sep 21, 2016 10:38:52 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version:        Apache Tomcat/8.0.37
Sep 21, 2016 10:38:52 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Sep 1 2016 10:01:52 UTC
Sep 21, 2016 10:38:52 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:         8.0.37.0
Sep 21, 2016 10:38:52 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Mac OS X
Sep 21, 2016 10:38:52 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            10.11.6
Sep 21, 2016 10:38:52 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          x86_64
Sep 21, 2016 10:38:52 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             /Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/jre
Sep 21, 2016 10:38:52 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           1.8.0_102-b14
Sep 21, 2016 10:38:52 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
Sep 21, 2016 10:38:52 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         /Users/felipefaustino/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Sep 21, 2016 10:38:52 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         /Users/felipefaustino/Library/Tomcat
Sep 21, 2016 10:38:52 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=/Users/felipefaustino/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Sep 21, 2016 10:38:52 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=/Users/felipefaustino/Library/Tomcat
Sep 21, 2016 10:38:52 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=/Users/felipefaustino/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps
Sep 21, 2016 10:38:53 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=/Users/felipefaustino/Library/Tomcat/endorsed
Sep 21, 2016 10:38:53 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=UTF-8
Sep 21, 2016 10:38:53 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/felipefaustino/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
Sep 21, 2016 10:38:53 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Sep 21, 2016 10:38:53 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Sep 21, 2016 10:38:53 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Sep 21, 2016 10:38:53 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Sep 21, 2016 10:38:53 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 984 ms
Sep 21, 2016 10:38:53 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Sep 21, 2016 10:38:53 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.37
Sep 21, 2016 10:38:55 AM org.apache.jasper.servlet.TldScanner scanJars
INFO: 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.
Sep 21, 2016 10:38:55 AM org.apache.catalina.core.ApplicationContext log
INFO: Spring WebApplicationInitializers detected on classpath: [br.com.casadocodigo.loja.conf.ServletSpringMVC@43595034]
log4j:WARN No appenders could be found for logger (br.com.casadocodigo.loja.conf.ServletSpringMVC).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Sep 21, 2016 10:38:55 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'dispatcher'

JPAConfiguration.java

package br.com.casadocodigo.loja.conf;

import java.util.Properties;

import javax.persistence.EntityManagerFactory;

import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@EnableTransactionManagement
public class JPAConfiguration {

    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory(){
        //
        LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();        
        JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); //hibernate
        factoryBean.setJpaVendorAdapter(vendorAdapter);

        // configurando o acesso a bd
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setUsername("root");
        dataSource.setPassword("123");
        dataSource.setUrl("jdbc:mysql://127.0.0.1:8080/casadocodigo");
        dataSource.setDriverClassName("com.mysql.jdbc.Driver"); 

        factoryBean.setDataSource(dataSource);
        //configurando o Hibernate
        Properties props = new Properties();
        props.setProperty("hibernate.dialect" , "org.hibernate.dialect.MySQL5Dialect");
        props.setProperty("hibernate.show_sql", "true");
        props.setProperty("hibernate.hbm2ddl.auto", "update");

        factoryBean.setJpaProperties(props);
        factoryBean.setPackagesToScan("br.com.casadocodigo.loja.models");

        return factoryBean;
    }
    @Bean
    public JpaTransactionManager transactionManager(EntityManagerFactory emf){
        return new JpaTransactionManager(emf);
    }
}

ServletSpringMVC.java

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;
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[] {AppWebConfiguration.class,JPAConfiguration.class}; // indico onde esta a configuracao do MVC
    }

    @Override
    protected String[] getServletMappings() {
        return new String[] {"/"}; //configuracao para nao precisar digitar a barra 
    }

}

Classe Produto

package br.com.casadocodigo.loja.models;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity 
public class Produto {

    @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int id;
    private String titulo;
    private String descricao;
    private int paginas;

    public String getTitulo() {
        return titulo;
    }
    public void setTitulo(String titulo) {
        this.titulo = titulo;
    }
    public String getDescricao() {
        return descricao;
    }
    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }
    public int getPaginas() {
        return paginas;
    }
    public void setPaginas(int paginas) {
        this.paginas = paginas;
    }

}

arquivo pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>org.casadocodigo</groupId>
  <artifactId>casadocodigo</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>war</packaging>
  <build>
    <finalName>casadocodigo</finalName>
    <plugins>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.1.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-servlet-api</artifactId>
        <version>7.0.30</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp.jstl</groupId>
        <artifactId>jstl-api</artifactId>
        <version>1.2</version>
        <exclusions>
            <exclusion>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>jstl-impl</artifactId>
        <version>1.2</version>
        <exclusions>
            <exclusion>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
  <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.1</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>1.6.1</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.1</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>4.3.0.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.3.0.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate.javax.persistence</groupId>
    <artifactId>hibernate-jpa-2.1-api</artifactId>
    <version>1.0.0.Final</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>4.1.0.RELEASE</version>
</dependency>
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.5</version>
</dependency>
</dependencies>
</project>
5 respostas

Olá,

Aumente o tempo de timeout dele. Para fazer isso, clique duas vezes no Tomcat na aba Server. Então vai abrir a pagina de overview. Lá tem a opção Timeout para o start e o stop. Aumente o start para 180 segundos e tenta subir sua aplicação

ja coloquei até para 300s mas ainda assim fica na mensagem "Initializing Spring FrameworkServlet 'dispatcher'" até acontecer o Timeout

Não sei se essa informação é relevante, mas: se eu tirar a linha abaixo, consigo startar,

factoryBean.setPackagesToScan("br.com.casadocodigo.loja.models");

porem com erros no console:

SEVERE: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class br.com.casadocodigo.loja.conf.JPAConfiguration: Invocation of init method failed; nested exception is java.lang.IllegalStateException: No persistence units parsed from {classpath*:META-INF/persistence.xml}
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)

e quando tento acessar na URL, aparece a seguinte mensagem: HTTP Status 500 - Servlet.init() for servlet dispatcher threw exception

Eu tive o mesmo problema hoje. Consegui soluciona-lo verificando a minha conexão com o banco de dados. Por alguma razão, o postgresql (banco que estou utilizando em meu curso), não estava permitindo a abertura novas sessões.

Após reinicialização do servidor (postgresql), minha aplicação passou a subir normalmente.

Também estive enfrentando o mesmo problema, como rodo um banco de dados externo numa hospedagem na digitalOcean que possuo, alterei o host do banco do dns para o ip da maquina e resolveu, aparentemente o eclipse não estava resolvendo ou estava demorando demais pra resolver. Colocando o ip subiu normal.