Spring Boot + Gradle + War + Standalone Tomcat:应用程序未加载

时间:2016-12-26 00:03:42

标签: spring tomcat gradle spring-boot war

在多次尝试解决下面这个简单的谜题后,我感到很沮丧。

我从spring.io创建了一个Web应用程序(war)。非常简单的演示,你可以看看这个git存储库:https://github.com/haigopi/SpringBootGradleStandaloneTomcatWarTest

Had only two classes (DemoApplication.java and ServletInitializer.java) 
and a Single application.properties.

运行gradle build将生成一个demo.war(也提交到存储库),我将其复制到tomcat(7 / CentOs)webapps,然后启动服务器。

以下是我的tomcat日志的树结构:

[root@localhost logs]# tree
.
├── catalina.2016-12-25.log
├── host-manager.2016-12-25.log
├── localhost.2016-12-25.log
├── localhost_access_log.2016-12-25.txt
└── manager.2016-12-25.log
在我盯着服务器后,

localhost.2016-12-25.log文件得到了以下日志:

Dec 25, 2016 5:26:31 PM org.apache.catalina.core.ApplicationContext log
INFO: 2 Spring WebApplicationInitializers detected on classpath
Dec 25, 2016 5:26:33 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring embedded WebApplicationContext

所以catalina.2016-12-25.log:

INFO: Starting Servlet Engine: Apache Tomcat/7.0.69
Dec 25, 2016 5:26:30 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /var/lib/tomcat/webapps/demo-0.0.1-SNAPSHOT.war
Dec 25, 2016 5:26:31 PM org.apache.catalina.startup.TldConfig execute
INFO: 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.
Dec 25, 2016 5:26:35 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive /var/lib/tomcat/webapps/demo-0.0.1-SNAPSHOT.war has finished in 5,599 ms
Dec 25, 2016 5:26:35 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Dec 25, 2016 5:26:35 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Dec 25, 2016 5:26:35 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 5650 ms

我没有看到弹簧启动应用程序启动时没有打印任何sysouts(来自DemoApplication.java和ServletInitializer),也没有弹簧启动横幅,我也尝试添加一个无法访问的控制器。

有人可以解雇一些吗?

快速查看我正在打印war文件的结构:

[root@localhost demo-0.0.1-SNAPSHOT]# tree
.
├── META-INF
│   └── MANIFEST.MF
├── org
│   └── springframework
│       └── boot
│           └── loader
│               ├── archive
│               │   ├── Archive.class
│               │   ├── Archive$Entry.class
│               │   ├── Archive$EntryFilter.class
│               │   ├── ExplodedArchive$1.class
│               │   ├── ExplodedArchive.class
│               │   ├── ExplodedArchive$FileEntry.class
│               │   ├── ExplodedArchive$FileEntryIterator.class
│               │   ├── ExplodedArchive$FileEntryIterator$EntryComparator.class
│               │   ├── JarFileArchive.class
│               │   ├── JarFileArchive$EntryIterator.class
│               │   └── JarFileArchive$JarFileEntry.class
│               ├── data
│               │   ├── ByteArrayRandomAccessData.class
│               │   ├── RandomAccessData.class
│               │   ├── RandomAccessDataFile.class
│               │   ├── RandomAccessDataFile$DataInputStream.class
│               │   ├── RandomAccessDataFile$FilePool.class
│               │   └── RandomAccessData$ResourceAccess.class
│               ├── ExecutableArchiveLauncher$1.class
│               ├── ExecutableArchiveLauncher.class
│               ├── jar
│               │   ├── AsciiBytes.class
│               │   ├── Bytes.class
│               │   ├── CentralDirectoryEndRecord.class
│               │   ├── CentralDirectoryFileHeader.class
│               │   ├── CentralDirectoryParser.class
│               │   ├── CentralDirectoryVisitor.class
│               │   ├── FileHeader.class
│               │   ├── Handler.class
│               │   ├── JarEntry.class
│               │   ├── JarEntryFilter.class
│               │   ├── JarFile$1.class
│               │   ├── JarFile$2.class
│               │   ├── JarFile$3.class
│               │   ├── JarFile.class
│               │   ├── JarFileEntries$1.class
│               │   ├── JarFileEntries.class
│               │   ├── JarFileEntries$EntryIterator.class
│               │   ├── JarFile$JarFileType.class
│               │   ├── JarURLConnection$1.class
│               │   ├── JarURLConnection.class
│               │   ├── JarURLConnection$JarEntryName.class
│               │   └── ZipInflaterInputStream.class
│               ├── JarLauncher.class
│               ├── LaunchedURLClassLoader$1.class
│               ├── LaunchedURLClassLoader.class
│               ├── Launcher.class
│               ├── MainMethodRunner.class
│               ├── PropertiesLauncher$1.class
│               ├── PropertiesLauncher$ArchiveEntryFilter.class
│               ├── PropertiesLauncher.class
│               ├── PropertiesLauncher$FilteredArchive$1.class
│               ├── PropertiesLauncher$FilteredArchive.class
│               ├── PropertiesLauncher$PrefixMatchingArchiveFilter.class
│               ├── util
│               │   └── SystemPropertyUtils.class
│               └── WarLauncher.class
└── WEB-INF
    ├── classes
    │   ├── application.properties
    │   ├── com
    │   │   └── example
    │   │       ├── DemoApplication.class
    │   │       └── ServletInitializer.class
    │   ├── static
    │   └── templates
    ├── lib
    │   ├── classmate-1.3.3.jar
    │   ├── hibernate-validator-5.2.4.Final.jar
    │   ├── jackson-annotations-2.8.5.jar
    │   ├── jackson-core-2.8.5.jar
    │   ├── jackson-databind-2.8.5.jar
    │   ├── jboss-logging-3.3.0.Final.jar
    │   ├── jcl-over-slf4j-1.7.22.jar
    │   ├── jul-to-slf4j-1.7.22.jar
    │   ├── log4j-over-slf4j-1.7.22.jar
    │   ├── logback-classic-1.1.8.jar
    │   ├── logback-core-1.1.8.jar
    │   ├── slf4j-api-1.7.22.jar
    │   ├── snakeyaml-1.17.jar
    │   ├── spring-aop-5.0.0.BUILD-SNAPSHOT.jar
    │   ├── spring-beans-5.0.0.BUILD-SNAPSHOT.jar
    │   ├── spring-boot-2.0.0.BUILD-SNAPSHOT.jar
    │   ├── spring-boot-autoconfigure-2.0.0.BUILD-SNAPSHOT.jar
    │   ├── spring-boot-starter-2.0.0.BUILD-SNAPSHOT.jar
    │   ├── spring-boot-starter-logging-2.0.0.BUILD-SNAPSHOT.jar
    │   ├── spring-boot-starter-web-2.0.0.BUILD-SNAPSHOT.jar
    │   ├── spring-context-5.0.0.BUILD-SNAPSHOT.jar
    │   ├── spring-core-5.0.0.BUILD-SNAPSHOT.jar
    │   ├── spring-expression-5.0.0.BUILD-SNAPSHOT.jar
    │   ├── spring-web-5.0.0.BUILD-SNAPSHOT.jar
    │   ├── spring-webmvc-5.0.0.BUILD-SNAPSHOT.jar
    │   └── validation-api-1.1.0.Final.jar
    └── lib-provided
        ├── spring-boot-starter-tomcat-2.0.0.BUILD-SNAPSHOT.jar
        ├── tomcat-embed-core-8.5.6.jar
        ├── tomcat-embed-el-8.5.6.jar
        └── tomcat-embed-websocket-8.5.6.jar

和清单文件:

[root@localhost META-INF]# cat MANIFEST.MF 
Manifest-Version: 1.0
Start-Class: com.example.DemoApplication
Spring-Boot-Classes: WEB-INF/classes/
Spring-Boot-Lib: WEB-INF/lib/
Spring-Boot-Version: 2.0.0.BUILD-SNAPSHOT
Main-Class: org.springframework.boot.loader.WarLauncher

0 个答案:

没有答案