Tomcat7不会初始化我的spring配置

时间:2018-10-24 20:55:00

标签: java spring

我有一个简单的maven spring项目,当我在tomcat服务器上运行该项目时,我看不到tomcat在启动时加载配置。

maven dependencies tomcat web application manager

MySpringMvcDispatcherServletInitializer.java
package com.abc.xyz.config;

import 
 org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

public class MySpringMvcDispatcherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Class<?>[] getRootConfigClasses() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[] { DemoAppConfig.class };
    }

    @Override
    protected String[] getServletMappings() {
        return new String[] { "/" };
    }

}
  

DemoAppConfig.java

package com.abc.xyz.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

    @Configuration
    @EnableWebMvc
    @ComponentScan("com.abc.xyz")

    public class DemoAppConfig implements WebMvcConfigurer {

    }
  

DemoRestController.java

package com.abc.xyz.rest;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class DemoRestController {

    // add code for the "/hello" endpoint

    @GetMapping("/hello")
    public String sayHello() {
        return "Hello World!";
    }

}
  

tomcat7启动日志

Oct 24, 2018 4:15:45 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:spring-rest-demo' did not find a matching property.
Oct 24, 2018 4:15:45 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:SIT_Dashboard' did not find a matching property.
Oct 24, 2018 4:15:45 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version:        Apache Tomcat/7.0.82
Oct 24, 2018 4:15:45 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Sep 29 2017 12:23:15 UTC
Oct 24, 2018 4:15:45 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:         7.0.82.0
Oct 24, 2018 4:15:45 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Windows 7
Oct 24, 2018 4:15:45 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            6.1
Oct 24, 2018 4:15:45 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
Oct 24, 2018 4:15:45 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             C:\FAST\JDK64\LINKS\JDK8\jre
Oct 24, 2018 4:15:45 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           1.8.0_144-b01
Oct 24, 2018 4:15:45 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
Oct 24, 2018 4:15:45 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         C:\FAST\ApacheTomcat\7.0.82\apache-tomcat-7.0.82
Oct 24, 2018 4:15:45 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         C:\FAST\ApacheTomcat\7.0.82\apache-tomcat-7.0.82
Oct 24, 2018 4:15:45 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=C:\FAST\ApacheTomcat\7.0.82\apache-tomcat-7.0.82
Oct 24, 2018 4:15:45 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\FAST\ApacheTomcat\7.0.82\apache-tomcat-7.0.82
Oct 24, 2018 4:15:45 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=C:\FAST\ApacheTomcat\7.0.82\apache-tomcat-7.0.82\wtpwebapps
Oct 24, 2018 4:15:45 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\FAST\ApacheTomcat\7.0.82\apache-tomcat-7.0.82\endorsed
Oct 24, 2018 4:15:45 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
Oct 24, 2018 4:15:45 PM 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:\FAST\JDK64\LINKS\JDK8\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\FAST\JDK64\1.8.0.144\bin;C:\ProgramData\Oracle\Java\javapath;C:\oracle\product\11.2.0\client_64\BIN\;C:\Program Files\Micro Focus\Reflection\;C:\Program Files (x86)\Micro Focus\Reflection\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\1E\SMSNomad\;C:\Program Files\aim\aim-install\bin\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Git\cmd;C:\FAST\nodejs\6.11.4\;C:\Program Files\TortoiseSVN\bin;C:\opt\gate\base91\..\perl\bin;C:\Users\R633368\AppData\Roaming\npm;C:\FAST\maven\3.5.0\apache-maven-3.5.0\bin;.
Oct 24, 2018 4:15:45 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Oct 24, 2018 4:15:45 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Oct 24, 2018 4:15:45 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 768 ms
Oct 24, 2018 4:15:45 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Oct 24, 2018 4:15:45 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.82
Oct 24, 2018 4:15:46 PM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
WARNING: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [472] milliseconds.
Oct 24, 2018 4:15:47 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\FAST\ApacheTomcat\7.0.82\apache-tomcat-7.0.82\webapps\docs
Oct 24, 2018 4:15:47 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\FAST\ApacheTomcat\7.0.82\apache-tomcat-7.0.82\webapps\docs has finished in 101 ms
Oct 24, 2018 4:15:47 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\FAST\ApacheTomcat\7.0.82\apache-tomcat-7.0.82\webapps\examples
Oct 24, 2018 4:15:47 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Oct 24, 2018 4:15:47 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Oct 24, 2018 4:15:47 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache@6d4352bf')
Oct 24, 2018 4:15:47 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\FAST\ApacheTomcat\7.0.82\apache-tomcat-7.0.82\webapps\examples has finished in 499 ms
Oct 24, 2018 4:15:47 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\FAST\ApacheTomcat\7.0.82\apache-tomcat-7.0.82\webapps\host-manager
Oct 24, 2018 4:15:47 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\FAST\ApacheTomcat\7.0.82\apache-tomcat-7.0.82\webapps\host-manager has finished in 157 ms
Oct 24, 2018 4:15:47 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\FAST\ApacheTomcat\7.0.82\apache-tomcat-7.0.82\webapps\manager
Oct 24, 2018 4:15:47 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\FAST\ApacheTomcat\7.0.82\apache-tomcat-7.0.82\webapps\manager has finished in 82 ms
Oct 24, 2018 4:15:47 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\FAST\ApacheTomcat\7.0.82\apache-tomcat-7.0.82\webapps\ROOT
Oct 24, 2018 4:15:48 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\FAST\ApacheTomcat\7.0.82\apache-tomcat-7.0.82\webapps\ROOT has finished in 77 ms
Oct 24, 2018 4:15:48 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Oct 24, 2018 4:15:48 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Oct 24, 2018 4:15:48 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2191 ms

如您所见,启动并没有显示它读过我的spring配置,请帮忙,谢谢

tomcat web application manager

  

已更新:我有一个临时修复程序(哇,由于项目中完全没有错误,我花了2天的时间来取得一些进展)。

     

这是诀窍:右键单击项目=>属性=>部署   程序集=>添加=>选择Java构建路径条目=>选择Maven   Dependencies => apply =>确定

     

您可以看到服务器日志刷新,并且最终加载了spring   配置,如果您选中

     

tomcat主目录/ wtpwebapps / {项目名称} / WEB-INF / lib,您可以   查看所有Maven依赖项都复制到这里

     

到目前为止,看起来现在一切都很好,但是我发现   其他问题,每次我右键单击=> maven =>更新项目... =>它   会尝试删除tomcat主页中的依赖项(罐子)   目录/ wtpwebapps / {项目名称} / WEB-INF / lib,

     

如果您的项目在tomcat上运行,则会出现错误   因为这些罐子正在被使用。

     

但是,如果您停止服务器并更新项目,然后以服务器身份运行   再次,一切恢复正常,没有错误,没有弹簧配置   在服务器启动日志中,然后您必须再次执行相同的技巧。

     

我尝试了许多有关“行家项目更新将   删除“ tomcat服务器中的jar”,它们都不起作用。因此,如果有人   有此修复程序,请共享

0 个答案:

没有答案