最近在使用springboot搭建项目的时候遇到几个问题。给大家分享下。
1.使用springboot,将其发布上tomcat的时候,如果不剔除掉内嵌的tomcat的话会出错。
2017-11-29 13:34:22,497 org.apache.catalina.core.ContainerBase addChildInternal
SEVERE: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
原因是依赖的jar包中内嵌了tomcat。
compile "org.springframework.boot:spring-boot-starter-web:${springBootVersion}" compile 'org.apache.tomcat.embed:tomcat-embed-jasper'
将这两个换成如下的配置就可以了
compile ("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") { exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat' }
其中embed,是使用了jsp页面所以需要依赖的。
2.同时,也会报了另外一个错误。
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
这个错误出现的原因是,框架没有读到application.yml或者properties的配置文件。或者是没有写dataSource的相关配置信息。
首先,放入tomcat里的时候似乎会注意大小写的问题。我一开始,Application,首字母大写就报这个错。
然后,如果自己的springboot项目只想存放controller和页面的话。
就需要在启动的Application类上加注解
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
另外,似乎发上tomcat需要一个类
public class ServletInitializer extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Application.class); } }
这样就需要依赖
providedCompile "javax.servlet:javax.servlet-api:3.0.1"
最后文章的解决方式参考了下面的仁兄的帖子。
http://blog.csdn.net/wo541075754/article/details/73379962