Eclipse中的“mvn spring-boot:run”和“Add to Tomcat server”有什么区别?

时间:2016-01-07 14:57:20

标签: eclipse spring maven tomcat spring-boot

我从here下载了一个Spring-boot CXF Web服务示例。我可以使用以下方法在Eclipse中成功运行它: 右键点击项目>以> Maven构建...> 运行并设置目标: spring-boot:run

服务器启动,所有内容都会登录到控制台。

接下来我尝试在Eclipse中的Tomcat服务器上部署它(参见screenshot.png),但是当服务器启动时,Spring没有启动。没有Spring信息记录到控制台

根据日志中的行,它知道Spring应该开始。那么为什么它不能正常启动呢?

INFO: Spring WebApplicationInitializers detected on classpath: [org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration@4ed48c2]

整个日志:

Led 07, 2016 3:39:18 ODP. org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:spring-boot-sample-ws-cxf' did not find a matching property.
Led 07, 2016 3:39:18 ODP. org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version:        Apache Tomcat/8.0.28
Led 07, 2016 3:39:18 ODP. org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Oct 7 2015 18:25:21 UTC
Led 07, 2016 3:39:18 ODP. org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:         8.0.28.0
Led 07, 2016 3:39:18 ODP. org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Windows 10
Led 07, 2016 3:39:18 ODP. org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            10.0
Led 07, 2016 3:39:18 ODP. org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
Led 07, 2016 3:39:18 ODP. org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             C:\Program Files\Java\jdk1.8.0_60\jre
Led 07, 2016 3:39:18 ODP. org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           1.8.0_60-b27
Led 07, 2016 3:39:18 ODP. org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
Led 07, 2016 3:39:18 ODP. org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         C:\Users\cerny\JavaProjects\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Led 07, 2016 3:39:18 ODP. org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         C:\Program Files\Tomcat 8.0
Led 07, 2016 3:39:18 ODP. org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=C:\Users\cerny\JavaProjects\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Led 07, 2016 3:39:18 ODP. org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\Program Files\Tomcat 8.0
Led 07, 2016 3:39:18 ODP. org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=C:\Users\cerny\JavaProjects\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
Led 07, 2016 3:39:18 ODP. org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\Program Files\Tomcat 8.0\endorsed
Led 07, 2016 3:39:18 ODP. org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1250
Led 07, 2016 3:39:18 ODP. org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.8.0_60\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre1.8.0_65/bin/server;C:/Program Files/Java/jre1.8.0_65/bin;C:/Program Files/Java/jre1.8.0_65/lib/amd64;C:\Program Files\apache-maven-3.3.3\bin;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\eclipse;;.
Led 07, 2016 3:39:18 ODP. org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Led 07, 2016 3:39:18 ODP. org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Led 07, 2016 3:39:18 ODP. org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Led 07, 2016 3:39:18 ODP. org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Led 07, 2016 3:39:18 ODP. org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1036 ms
Led 07, 2016 3:39:18 ODP. org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Led 07, 2016 3:39:18 ODP. org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.28
Led 07, 2016 3:39:25 ODP. org.apache.jasper.servlet.TldScanner scanJars
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.
Led 07, 2016 3:39:25 ODP. org.apache.catalina.core.ApplicationContext log
INFO: Spring WebApplicationInitializers detected on classpath: [org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration@4ed48c2]
Led 07, 2016 3:39:25 ODP. org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Led 07, 2016 3:39:25 ODP. org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Led 07, 2016 3:39:25 ODP. org.apache.catalina.startup.Catalina start
INFO: Server startup in 7300 ms

2 个答案:

答案 0 :(得分:0)

从spring boot项目生成的jar会有tomcat服务器。您可以使用以下命令启动服务器

java -jar XXX.jar

答案 1 :(得分:0)

我找到了它无法启动的原因。现在它对我有用。要在eclipse tomcat上运行,您需要将extends SpringBootServletInitializer添加到项目的主类App.java

所以结果看起来像

package com.foo.bar;

import some.imported.package
import another.imported.package

@SpringBootApplication
public class App extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }

}