springboot+maven+tomcat问题

简介: 版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_26654727/article/details/78456345 问题背景版本介绍jdk1.7 、springboot:1.3.1.RELEASE、tomcat8 、maven3解决过程1. 搭建Springboot+jsp项目。
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_26654727/article/details/78456345

问题背景

版本介绍

jdk1.7 、springboot:1.3.1.RELEASE、tomcat8 、maven3

解决过程

1. 搭建Springboot+jsp项目。搭建Springboot项目之时,标准配置:
<modelVersion>4.0.0</modelVersion>
<artifactId>manage</artifactId>
<!--<version>1.0-SNAPSHOT</version>-->
<!-- 打war包,不使用springboot内置tomcat-->
<packaging>war</packaging> 

<dependencyManagement>
        <dependencies>
            <dependency>
                <!-- Import dependency management from Spring Boot -->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>1.3.1.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
</dependencyManagement>
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <!--移除内置tomcat,打war包-->
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
                <!--<exclusion>-->
                    <!--<groupId>ch.qos.logback</groupId>-->
                    <!--<artifactId>logback-classic</artifactId>-->
                <!--</exclusion>-->
            </exclusions>
        </dependency>
        <!--Springboot的监控-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!-- Spring Boot Test 依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
         <!--spring-boot-configuration:spring boot 配置处理器; -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
         <!--关于embed的容器 使用jsp时,必须的内容-->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
        <properties>
        <!-- 这里指定项目编码 -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>1.4.0.RELEASE</version>
            </plugin>
            <plugin>
                <!-- maven打包的时候告诉maven不需要web.xml,否刚会报找不到web.xml错误 -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                   <!--指定maven的编译器版本-->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
2. 在maven打包过程中出现了,有关ch.qos.logback版本的问题,而导致tomcat启动失败,故在pom文件中添加限制其版本
<!--logback版本问题导致tomcat启动失败-->
        <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.1.3</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-core</artifactId>
        <version>1.1.3</version>
            <scope>provided</scope>
        </dependency>
3.本地启动测试没问题,放至centos6.5进行测试,手动启动linux上同版本tomcat,tomcat报错:

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.

问题来源:
使用了CKEditor和CKFinder后,在lib里添加了很多jar包,打开相应页面出现以上问题。
org.apache.jasper.compiler.TldLocationsCache tldScanJar
信息: 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.
(1)有人说是 的问题,可是我的页面里根本就没有
(2)还有说,修改${TOMCAT_HOME}/bin/catalina.sh或${TOMCAT_HOME}/bin/catalina.bat文件,可是tomcat目录下没有这两个文件。
(3)还有说,调整${tomcat}/conf/catalina.properties,将提示的jar添加到不扫描清单中。没有试,而是通过下面的方法解决了。
最终解决:
修改$CATALINA_BASE/conf/catalina.properties文件,添加org.apache.el.parser.SKIP_IDENTIFIER_CHECK=true选项。

4.上述问题解决之后发现tomcat的catalina.out虽然正常运行,并且未出现任何问题。但任然无法访问页面,通过localhost_access_log.txt日志文件返回的结果都是404,但tomcat主界面却可以正常访问。

问题原因:
linux系统jdk版本与本地版本不一致,本地版本在调试过程中无意中设置成1.8.并且将maven编译器jdk编辑版本设置成1.8.导致两地版本不一致导致。

                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>

5.本调试过程中最大的问题:

本地启动正常,linux启动报错如下:

06-Nov-2017 10:48:12.336 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start: 
 org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/nrsmanage]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:753)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:729)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:976)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1853)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.helpers.NOPLoggerFactory loaded from file:/opt/nrs/apache-tomcat-8.0.47/webapps/nrsmanage/WEB-INF/lib/slf4j-api-1.7.21.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml Object of class [org.slf4j.helpers.NOPLoggerFactory] must be an instance of class ch.qos.logback.classic.LoggerContext

考虑到之前有关springboot对于不同版本日志文件冲突导致启动失败的问题,故一致在本地进行关于日志工具版本的调试,都未有结果,后静下心再考虑该日志文件所说内容,随后把该web项目lib包中有关logback相关的包进行删除,tomcat正常启动,并可以正常访问。
在本地服务中,可以在pom文件中的相关包设置

<scope>provided</scope>   该标签表示该包的级别,表示仅在编译级别支持。打包和运行过程中不含有此包。

总结

1.必须时刻记住版本的重要性,以及对于tomcat原理、maven原理、以及springboot原理的深究。
2.不要盲目的相信各种解决办法,因为不管是谁的解决方法都是在特定情况下发生的,我可以借鉴他的方法,但必须要考虑清楚本地问题的原因。想清楚解决方案,在进行操作,并注意做好备份,以及对自己各种操作过程要有个记录,可以做好 Rollback操作。

目录
相关文章
|
2月前
|
Java 程序员 API
Springboot-swagger配置(idea社区版2023.1.4+apache-maven-3.9.3-bin)
Springboot-swagger配置(idea社区版2023.1.4+apache-maven-3.9.3-bin)
59 1
|
2月前
|
前端开发 Java 数据库连接
Springboot-MyBatis配置-配置端口号与服务路径(idea社区版2023.1.4+apache-maven-3.9.3-bin)
Springboot-MyBatis配置-配置端口号与服务路径(idea社区版2023.1.4+apache-maven-3.9.3-bin)
33 0
|
15天前
|
前端开发 Java 应用服务中间件
Springboot对MVC、tomcat扩展配置
Springboot对MVC、tomcat扩展配置
|
23天前
|
Java 应用服务中间件
Springboot启动的时候初始化的线程池默认配置tomcat
Springboot启动的时候初始化的线程池默认配置tomcat
13 1
|
2月前
|
Java 应用服务中间件 程序员
互联网大厂为什么禁止SpringBoot项目使用Tomcat?
在SpringBoot框架中,我们使用最多的是Tomcat,这是SpringBoot默认的容器技术,而且是内嵌式的Tomcat。
50 1
互联网大厂为什么禁止SpringBoot项目使用Tomcat?
|
2月前
|
JSON Java Maven
SpringBoot使用git-commit-id-maven-plugin打包
【2月更文挑战第1天】 git-commit-id-maven-plugin 是一个maven 插件,用来在打包的时候将git-commit 信息打进jar中。 这样做的好处是可以将发布的某版本和对应的代码关联起来,方便查阅和线上项目的维护。至于它的作用,用官方说法,这个功能对于大型分布式项目来说是无价的。
85 0
|
2月前
|
安全 前端开发 程序员
Springboot-EolinkApikit一键生成注释与一键上传API接口(idea社区版2023.1.4+apache-maven-3.9.3-bin)
Springboot-EolinkApikit一键生成注释与一键上传API接口(idea社区版2023.1.4+apache-maven-3.9.3-bin)
18 0
|
1月前
|
Java Maven
手把手教你搭建Maven项目
手把手教你搭建Maven项目
31 0
|
2月前
|
Java Maven
java修改当前项目的maven仓库地址为国内
修改当前项目的maven仓库地址为国内
|
3月前
|
Dubbo Java 应用服务中间件
微服务框架(十)Maven Archetype制作Dubbo项目原型
  此系列文章将会描述Java框架Spring Boot、服务治理框架Dubbo、应用容器引擎Docker,及使用Spring Boot集成Dubbo、Mybatis等开源框架,其中穿插着Spring Boot中日志切面等技术的实现,然后通过gitlab-CI以持续集成为Docker镜像。   本文为Maven Archetype的制作及使用,使用archetype插件制作Dubbo项目原型

推荐镜像

更多