似乎spring-boot开始两次开发Web应用程序

问题描述 投票:1回答:1

我开始学习spring-boot来开发Web应用程序。

我正在使用的IDE是IDEA,服务器是Tomcat。

使用IDEA内置tomcat并运行项目时,它运行良好。

但是,使用下载的tomcat,spring-boot在IDEA的日志中启动两次。

然后我删除了内置tomcat的依赖项,并添加了[email protected]。它仍然无法正常工作。

我们认为

 <dependencies>        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

application.Java

@EnableTransactionManagement
@SpringBootApplication
@MapperScan("com.wolwo.*.service")
public class Application extends SpringBootServletInitializer {
    public static void main (String[] args) throws Exception{
        SpringApplication.run(Application.class,args);
    }
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        builder.sources(this.getClass());
        return super.configure(builder);
    }
}

日志

D:\java\apache-tomcat-8.0.51\bin\catalina.bat run
[2019-04-03 03:59:37,906] Artifact yyw:war: Waiting for server connection to start artifact deployment...
Using CATALINA_BASE:   "D:\java\apache-tomcat-8.0.51"
Using CATALINA_HOME:   "D:\java\apache-tomcat-8.0.51"
Using CATALINA_TMPDIR: "D:\java\apache-tomcat-8.0.51\temp"
Using JRE_HOME:        "D:\java\jdk1.8.0_171"
Using CLASSPATH:       "D:\java\apache-tomcat-8.0.51\bin\bootstrap.jar;D:\java\apache-tomcat-8.0.51\bin\tomcat-juli.jar"
03-Apr-2019 15:59:38.956 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.0.51
...
03-Apr-2019 15:59:38.970 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\java\jdk1.8.0_171\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\java\jdk1.8.0_171\bin;D:\java\jdk1.8.0_171\jre\bin;D:\java\apache-tomcat-8.0.51\bin;D:\java\apache-maven-3.5.3\bin;D:\soft\TortoiseSVN\bin;D:\soft\nvm;C:\Program Files\nodejs;D:\soft\putty\;D:\Gradle\gradle-5.3\bin;D:\java\spring-1.5.19.RELEASE\bin;D:\Git\cmd;C:\Users\hongYi\AppData\Local\Programs\Fiddler;D:\soft\nvm;C:\Program Files\nodejs;D:\Microsoft VS Code\bin;D:\java\apache-tomcat-8.0.51\bin;D:\java\apache-tomcat-8.0.51\lib;.
03-Apr-2019 15:59:39.115 信息 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
03-Apr-2019 15:59:39.132 信息 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
03-Apr-2019 15:59:39.136 信息 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
03-Apr-2019 15:59:39.139 信息 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
03-Apr-2019 15:59:39.142 信息 [main] org.apache.catalina.startup.Catalina.load Initialization processed in 657 ms
03-Apr-2019 15:59:39.180 信息 [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
03-Apr-2019 15:59:39.180 信息 [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.51
03-Apr-2019 15:59:39.191 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory D:\java\apache-tomcat-8.0.51\webapps\yyw
03-Apr-2019 15:59:42.076 信息 [localhost-startStop-1] 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.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v1.5.19.RELEASE)

15:59:43 [INFO ] method:org.springframework.boot.StartupInfoLogger.logStarting(StartupInfoLogger.java:48)
Starting Application v1.0-SNAPSHOT on hongYi-PC with PID 9116 (D:\java\apache-tomcat-8.0.51\webapps\yyw\WEB-INF\classes started by hongYi in D:\java\apache-tomcat-8.0.51\bin)
15:59:43 [INFO ] method:org.springframework.boot.SpringApplication.logStartupProfileInfo(SpringApplication.java:597)
The following profiles are active: dev
15:59:43 [INFO ] method:org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:583)
Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4883dfc0: startup date [Wed Apr 03 15:59:43 CST 2019]; root of context hierarchy
15:59:44 [INFO ] method:org.hibernate.validator.internal.util.Version.<clinit>(Version.java:30)
HV000001: Hibernate Validator 5.3.6.Final
15:59:45 [INFO ] method:org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.prepareEmbeddedWebApplicationContext(EmbeddedWebApplicationContext.java:287)
Root WebApplicationContext: initialization completed in 2002 ms
15:59:46 [INFO ] method:org.springframework.boot.web.servlet.ServletRegistrationBean.onStartup(ServletRegistrationBean.java:191)
Mapping servlet: 'dispatcherServlet' to [/]
15:59:46 [INFO ] method:org.springframework.boot.web.servlet.AbstractFilterRegistrationBean.configure(AbstractFilterRegistrationBean.java:259)
Mapping filter: 'errorPageFilter' to: [/*]
15:59:46 [INFO ] method:org.springframework.boot.web.servlet.AbstractFilterRegistrationBean.configure(AbstractFilterRegistrationBean.java:259)
Mapping filter: 'characterEncodingFilter' to: [/*]
15:59:46 [INFO ] method:org.springframework.boot.web.servlet.AbstractFilterRegistrationBean.configure(AbstractFilterRegistrationBean.java:259)
Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
15:59:46 [INFO ] method:org.springframework.boot.web.servlet.AbstractFilterRegistrationBean.configure(AbstractFilterRegistrationBean.java:259)
Mapping filter: 'httpPutFormContentFilter' to: [/*]
15:59:46 [INFO ] method:org.springframework.boot.web.servlet.AbstractFilterRegistrationBean.configure(AbstractFilterRegistrationBean.java:259)
Mapping filter: 'requestContextFilter' to: [/*]
15:59:48 [INFO ] method:org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.initControllerAdviceCache(RequestMappingHandlerAdapter.java:556)
Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4883dfc0: startup date [Wed Apr 03 15:59:43 CST 2019]; root of context hierarchy
15:59:48 [INFO ] method:org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.register(AbstractHandlerMethodMapping.java:544)
Mapped "{[/patient/login]}" onto public com.wolwo.base.util.JsonResult com.wolwo.patient.controller.PatientController.login()
15:59:48 [INFO ] method:org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.register(AbstractHandlerMethodMapping.java:544)
03-Apr-2019 15:59:49.080 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory D:\java\apache-tomcat-8.0.51\webapps\yyw has finished in 9,888 ms
Mapped "{[/ || /index]}" onto public com.wolwo.base.util.JsonResult com.wolwo.sample.controller.TestController.index()
15:59:48 [INFO ] method:org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.register(AbstractHandlerMethodMapping.java:544)
Mapped "{[/wx/wxCallback]}" onto public void com.wolwo.wx.controller.WxCommonController.workWxcheck(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException,com.wolwo.wx.util.AesException
15:59:48 [INFO ] method:org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.register(AbstractHandlerMethodMapping.java:544)
Mapped "{[/wx/auth]}" onto public void com.wolwo.wx.controller.WxCommonController.wxAuth(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws javax.servlet.ServletException,java.io.IOException
15:59:48 [INFO ] method:org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.register(AbstractHandlerMethodMapping.java:544)
Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
15:59:48 [INFO ] method:org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.register(AbstractHandlerMethodMapping.java:544)
Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
15:59:48 [INFO ] method:org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:362)
Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
15:59:48 [INFO ] method:org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:362)
Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
15:59:48 [INFO ] method:org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:362)
Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
15:59:49 [INFO ] method:org.springframework.boot.StartupInfoLogger.logStarted(StartupInfoLogger.java:57)
Started Application in 6.649 seconds (JVM running for 11.081)
03-Apr-2019 15:59:49.100 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
03-Apr-2019 15:59:49.124 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
03-Apr-2019 15:59:49.128 信息 [main] org.apache.catalina.startup.Catalina.start Server startup in 9984 ms
Connected to server
[2019-04-03 03:59:49,165] Artifact yyw:war: Artifact is being deployed, please wait...
15:59:49 [INFO ] method:org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:984)
Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4883dfc0: startup date [Wed Apr 03 15:59:43 CST 2019]; root of context hierarchy

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v1.5.19.RELEASE)

15:59:51 [INFO ] method:org.springframework.boot.StartupInfoLogger.logStarting(StartupInfoLogger.java:48)
Starting Application v1.0-SNAPSHOT on hongYi-PC with PID 9116 (D:\java\apache-tomcat-8.0.51\webapps\yyw\WEB-INF\classes started by hongYi in D:\java\apache-tomcat-8.0.51\bin)
15:59:51 [INFO ] method:org.springframework.boot.SpringApplication.logStartupProfileInfo(SpringApplication.java:597)
The following profiles are active: dev
15:59:52 [INFO ] method:org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:583)
Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7bbafc0d: startup date [Wed Apr 03 15:59:52 CST 2019]; root of context hierarchy
15:59:52 [INFO ] method:org.hibernate.validator.internal.util.Version.<clinit>(Version.java:30)
HV000001: Hibernate Validator 5.3.6.Final
15:59:53 [INFO ] method:org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.prepareEmbeddedWebApplicationContext(EmbeddedWebApplicationContext.java:287)
Root WebApplicationContext: initialization completed in 1643 ms
15:59:54 [INFO ] method:org.springframework.boot.web.servlet.ServletRegistrationBean.onStartup(ServletRegistrationBean.java:191)
Mapping servlet: 'dispatcherServlet' to [/]
15:59:54 [INFO ] method:org.springframework.boot.web.servlet.AbstractFilterRegistrationBean.configure(AbstractFilterRegistrationBean.java:259)
Mapping filter: 'errorPageFilter' to: [/*]
15:59:54 [INFO ] method:org.springframework.boot.web.servlet.AbstractFilterRegistrationBean.configure(AbstractFilterRegistrationBean.java:259)
Mapping filter: 'characterEncodingFilter' to: [/*]
15:59:54 [INFO ] method:org.springframework.boot.web.servlet.AbstractFilterRegistrationBean.configure(AbstractFilterRegistrationBean.java:259)
Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
15:59:54 [INFO ] method:org.springframework.boot.web.servlet.AbstractFilterRegistrationBean.configure(AbstractFilterRegistrationBean.java:259)
Mapping filter: 'httpPutFormContentFilter' to: [/*]
15:59:54 [INFO ] method:org.springframework.boot.web.servlet.AbstractFilterRegistrationBean.configure(AbstractFilterRegistrationBean.java:259)
Mapping filter: 'requestContextFilter' to: [/*]
...
15:59:56 [INFO ] method:org.springframework.boot.StartupInfoLogger.logStarted(StartupInfoLogger.java:57)
Started Application in 5.303 seconds (JVM running for 18.703)
[2019-04-03 03:59:57,206] Artifact yyw:war: Artifact is deployed successfully
[2019-04-03 03:59:57,207] Artifact yyw:war: Deploy took 8,042 milliseconds

application.yml

spring:
  profiles:
    active: dev

---
spring:
  profiles: dev
  datasource:
    platform: mysql
    url: jdbc:mysql://localhost:3306/localcstm10?useSSL=false
    username: root
    password: root
---
server:
  port: 8080
  context-path: /yyw
spring:
  jmx:
    enabled: false
  mvc:
    view:
      prefix: /WEB-INF/jsp/
      suffix: .jsp

mybatis:
  mapperLocations: classpath:mybatis/*.xml

server.xml中

<?xml version="1.0" encoding="UTF-8"?>

<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -->

<!-- Note: A "Server" is not itself a "Container", so you may not define subcomponents such as "Valves" at this level. Documentation at /docs/config/server.html -->

<!--顶层类元素,可以包含多个Service-->

-<Server shutdown="SHUTDOWN" port="8005">

<Listener className="org.apache.catalina.startup.VersionLoggerListener"/>

<!-- Security listener. Documentation at /docs/config/listeners.html <Listener className="org.apache.catalina.security.SecurityListener" /> -->

<!--APR library loader. Documentation at /docs/apr.html -->

<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on"/>

<!-- Prevent memory leaks due to use of particular java/javax APIs-->

<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>

<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>

<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>

<!-- Global JNDI resources Documentation at /docs/jndi-resources-howto.html -->

-<GlobalNamingResources>

<!-- Editable user database that can also be used by UserDatabaseRealm to authenticate users -->

<Resource type="org.apache.catalina.UserDatabase" pathname="conf/tomcat-users.xml" name="UserDatabase" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" description="User database that can be updated and saved" auth="Container"/>
</GlobalNamingResources>
-<Service name="Catalina">
<Connector port="8080" redirectPort="8443" protocol="HTTP/1.1" connectionTimeout="20000"/>

<Connector port="8009" redirectPort="8443" protocol="AJP/1.3"/>

-<Engine name="Catalina" defaultHost="localhost">


-<Realm className="org.apache.catalina.realm.LockOutRealm">

<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<!--容器类元素,为特定的虚拟主机组件处理客户请求-->
-<Host name="localhost" unpackWARs="true" autoDeploy="true" appBase="webapps">
<Valve className="org.apache.catalina.valves.AccessLogValve" suffix=".txt" prefix="localhost_access_log" pattern="%h %l %u %t "%r" %s %b" directory="logs"/>

</Host>
</Engine>
</Service>
</Server>
java spring-boot intellij-idea
1个回答
1
投票

您已将应用程序部署了两次,因为它作为展开的目录和jar / war文件存在

 Deploying web application directory D:\java\apache-tomcat-8.0.51\webapps\yyw

[2019-04-03 03:59:49,165] Artifact yyw:war: Artifact is being deployed, please wait...

删除其中一个。

© www.soinside.com 2019 - 2024. All rights reserved.