最近用springboot框架,通过tomcat4e启动遇到的错误。

最近在使用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


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值