首页 > 代码库 > Springmvc+Hibernate在Eclipse启动Tomcat需要很长时间的解决方法

Springmvc+Hibernate在Eclipse启动Tomcat需要很长时间的解决方法

  最近在学习SpringMvc开发,有一个提问困扰了很久,就是在Eclipse启动Tomcat需要很长时间,大概要1分多钟。

      启动日志:

九月 08, 2016 8:59:01 下午 org.apache.catalina.startup.VersionLoggerListener log信息: Server version:        Apache Tomcat/8.0.36九月 08, 2016 8:59:01 下午 org.apache.catalina.startup.VersionLoggerListener log信息: Server built:          Jun 9 2016 13:55:50 UTC九月 08, 2016 8:59:01 下午 org.apache.catalina.startup.VersionLoggerListener log信息: Server number:         8.0.36.0九月 08, 2016 8:59:01 下午 org.apache.catalina.startup.VersionLoggerListener log信息: OS Name:               Windows Server 2012 R2九月 08, 2016 8:59:01 下午 org.apache.catalina.startup.VersionLoggerListener log信息: OS Version:            6.3九月 08, 2016 8:59:01 下午 org.apache.catalina.startup.VersionLoggerListener log信息: Architecture:          amd64九月 08, 2016 8:59:01 下午 org.apache.catalina.startup.VersionLoggerListener log信息: Java Home:             D:\jdk1.8.0_65\jre九月 08, 2016 8:59:01 下午 org.apache.catalina.startup.VersionLoggerListener log信息: JVM Version:           1.8.0_65-b17九月 08, 2016 8:59:01 下午 org.apache.catalina.startup.VersionLoggerListener log信息: JVM Vendor:            Oracle Corporation九月 08, 2016 8:59:01 下午 org.apache.catalina.startup.VersionLoggerListener log信息: CATALINA_BASE:         E:\CaiHao4\trunk\Java\.metadata\.plugins\org.eclipse.wst.server.core\tmp1九月 08, 2016 8:59:01 下午 org.apache.catalina.startup.VersionLoggerListener log信息: CATALINA_HOME:         D:\tomcat-8九月 08, 2016 8:59:01 下午 org.apache.catalina.startup.VersionLoggerListener log信息: Command line argument: -Dcatalina.base=E:\CaiHao4\trunk\Java\.metadata\.plugins\org.eclipse.wst.server.core\tmp1九月 08, 2016 8:59:01 下午 org.apache.catalina.startup.VersionLoggerListener log信息: Command line argument: -Dcatalina.home=D:\tomcat-8九月 08, 2016 8:59:01 下午 org.apache.catalina.startup.VersionLoggerListener log信息: Command line argument: -Dwtp.deploy=E:\CaiHao4\trunk\Java\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps九月 08, 2016 8:59:01 下午 org.apache.catalina.startup.VersionLoggerListener log信息: Command line argument: -Djava.endorsed.dirs=D:\tomcat-8\endorsed九月 08, 2016 8:59:01 下午 org.apache.catalina.startup.VersionLoggerListener log信息: Command line argument: -Dfile.encoding=UTF-8九月 08, 2016 8:59:01 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\jdk1.8.0_65\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:/jdk1.8.0_65/bin/../jre/bin/server;D:/jdk1.8.0_65/bin/../jre/bin;D:/jdk1.8.0_65/bin/../jre/lib/amd64;C:\Program Files (x86)\Common Files\NetSarang;D:\apache-maven-3.3.3\bin;D:\jdk1.8.0_65\bin;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;D:\eclipse-jee-neon;;.九月 08, 2016 8:59:02 下午 org.apache.coyote.AbstractProtocol init信息: Initializing ProtocolHandler ["http-nio-8080"]九月 08, 2016 8:59:02 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector信息: Using a shared selector for servlet write/read九月 08, 2016 8:59:02 下午 org.apache.coyote.AbstractProtocol init信息: Initializing ProtocolHandler ["ajp-nio-8009"]九月 08, 2016 8:59:02 下午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector信息: Using a shared selector for servlet write/read九月 08, 2016 8:59:02 下午 org.apache.catalina.startup.Catalina load信息: Initialization processed in 1384 ms九月 08, 2016 8:59:02 下午 org.apache.catalina.core.StandardService startInternal信息: Starting service Catalina九月 08, 2016 8:59:02 下午 org.apache.catalina.core.StandardEngine startInternal信息: Starting Servlet Engine: Apache Tomcat/8.0.36九月 08, 2016 8:59:02 下午 org.apache.catalina.startup.HostConfig deployDescriptor信息: Deploying configuration descriptor E:\CaiHao4\trunk\Java\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\conf\Catalina\localhost\web-city.xml九月 08, 2016 8:59:02 下午 org.apache.catalina.startup.SetContextPropertiesRule begin警告: [SetContextPropertiesRule]{Context} Setting property ‘source‘ to ‘org.eclipse.jst.j2ee.server:web-city‘ did not find a matching property.九月 08, 2016 8:59:05 下午 org.apache.jasper.servlet.TldScanner scanJars信息: 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.九月 08, 2016 8:59:05 下午 org.apache.catalina.core.ApplicationContext log信息: 1 Spring WebApplicationInitializers detected on classpath九月 08, 2016 8:59:05 下午 org.apache.catalina.core.ApplicationContext log信息: Initializing Spring root WebApplicationContext九月 08, 2016 8:59:05 下午 org.springframework.web.context.ContextLoader initWebApplicationContext信息: Root WebApplicationContext: initialization started九月 08, 2016 8:59:05 下午 org.springframework.web.context.support.AnnotationConfigWebApplicationContext prepareRefresh信息: Refreshing Root WebApplicationContext: startup date [Thu Sep 08 20:59:05 CST 2016]; root of context hierarchy九月 08, 2016 8:59:05 下午 org.springframework.web.context.support.AnnotationConfigWebApplicationContext loadBeanDefinitions信息: Registering annotated classes: [class com.caihao.city.spring.config.RootConfig]九月 08, 2016 8:59:05 下午 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor <init>信息: JSR-330 ‘javax.inject.Inject‘ annotation found and supported for autowiring九月 08, 2016 8:59:06 下午 org.hibernate.Version logVersionINFO: HHH000412: Hibernate Core {5.2.2.Final}九月 08, 2016 8:59:06 下午 org.hibernate.cfg.Environment <clinit>INFO: HHH000206: hibernate.properties not found九月 08, 2016 8:59:06 下午 org.hibernate.cfg.Environment buildBytecodeProviderINFO: HHH000021: Bytecode provider name : javassist九月 08, 2016 8:59:06 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}九月 08, 2016 9:00:27 下午 org.hibernate.dialect.Dialect <init>INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect九月 08, 2016 9:00:29 下午 org.springframework.web.context.ContextLoader initWebApplicationContext信息: Root WebApplicationContext: initialization completed in 84077 ms九月 08, 2016 9:00:29 下午 org.apache.catalina.core.ApplicationContext log信息: Initializing Spring FrameworkServlet ‘dispatcher‘九月 08, 2016 9:00:29 下午 org.springframework.web.servlet.DispatcherServlet initServletBean信息: FrameworkServlet ‘dispatcher‘: initialization started九月 08, 2016 9:00:29 下午 org.springframework.web.context.support.AnnotationConfigWebApplicationContext prepareRefresh信息: Refreshing WebApplicationContext for namespace ‘dispatcher-servlet‘: startup date [Thu Sep 08 21:00:29 CST 2016]; parent: Root WebApplicationContext九月 08, 2016 9:00:29 下午 org.springframework.web.context.support.AnnotationConfigWebApplicationContext loadBeanDefinitions信息: Registering annotated classes: [class com.caihao.city.spring.config.WebConfig]九月 08, 2016 9:00:29 下午 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor <init>信息: JSR-330 ‘javax.inject.Inject‘ annotation found and supported for autowiring九月 08, 2016 9:00:30 下午 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache信息: Looking for @ControllerAdvice: WebApplicationContext for namespace ‘dispatcher-servlet‘: startup date [Thu Sep 08 21:00:29 CST 2016]; parent: Root WebApplicationContext九月 08, 2016 9:00:30 下午 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping register信息: Mapped "{[/],methods=[GET]}" onto public java.lang.String com.caihao.city.controller.HomeController.index(org.springframework.ui.Model)九月 08, 2016 9:00:30 下午 org.springframework.web.servlet.handler.SimpleUrlHandlerMapping registerHandler信息: Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler]SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".SLF4J: Defaulting to no-operation (NOP) logger implementationSLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.九月 08, 2016 9:00:30 下午 org.springframework.web.servlet.DispatcherServlet initServletBean信息: FrameworkServlet ‘dispatcher‘: initialization completed in 1088 ms九月 08, 2016 9:00:30 下午 org.apache.catalina.startup.HostConfig deployDescriptor信息: Deployment of configuration descriptor E:\CaiHao4\trunk\Java\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\conf\Catalina\localhost\web-city.xml has finished in 87,789 ms九月 08, 2016 9:00:30 下午 org.apache.coyote.AbstractProtocol start信息: Starting ProtocolHandler ["http-nio-8080"]九月 08, 2016 9:00:30 下午 org.apache.coyote.AbstractProtocol start信息: Starting ProtocolHandler ["ajp-nio-8009"]九月 08, 2016 9:00:30 下午 org.apache.catalina.startup.Catalina start信息: Server startup in 88457 ms

    Spring配置:

@Bean    public DataSource dataSource(){        BasicDataSource dataSource = new BasicDataSource();        dataSource.setDriverClassName(env.getRequiredProperty("jdbc.driverClassName"));        dataSource.setUrl(env.getRequiredProperty("jdbc.url"));        dataSource.setUsername(env.getRequiredProperty("jdbc.username"));        dataSource.setPassword(env.getRequiredProperty("jdbc.password"));        dataSource.setInitialSize(env.getRequiredProperty("jdbc.initialSize", Integer.class));        dataSource.setMaxIdle(env.getRequiredProperty("jdbc.maxIdle", Integer.class));        return dataSource;    }        @Bean    public LocalSessionFactoryBean sessionFactory(DataSource dataSource){        LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean();        factoryBean.setDataSource(dataSource);        factoryBean.setMappingResources(new String[]{                "com/caihao/hibernate/caihao.hbm.xml"                });        Properties props = new Properties();        props.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");        props.setProperty("hibernate.show_sql", "true");        props.setProperty("hibernate.jdbc.fetch_size", "50");        factoryBean.setHibernateProperties(props);        return factoryBean;    }

    解决方法添加:

    props.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false");

    参考:http://stackoverflow.com/questions/14445838/hibernate-startup-very-slow

Springmvc+Hibernate在Eclipse启动Tomcat需要很长时间的解决方法