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

时间:2022-03-19 16:32:30

  最近在学习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 logVersion
INFO: 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 buildBytecodeProvider
INFO: 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 implementation
SLF4J: 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://*.com/questions/14445838/hibernate-startup-very-slow