简体   繁体   English

在独立Tomcat上部署时,为什么没有提取我的RequestMapping? 它可以在Eclipse WTP中使用

[英]Why are my RequestMapping not being picked up when deploying on Standalone Tomcat? It works in Eclipse WTP

I am deploying a Spring MVC webapp on Tomcat8 using RequestMapping annotation. 我正在使用RequestMapping注释在Tomcat8上部署Spring MVC Web应用程序。 Example of Mappings: 映射示例:

@Controller("brandController")
@RequestMapping("brand")
public class BrandController {

@Autowired
private BrandService brandService;


/**
 * Creates or edits details about a specific Brand
 * @param brand the brand to create/edit
 */
@RequestMapping(value="/save", consumes="application/json",  produces="application/json", method=RequestMethod.POST)
public @ResponseBody Brand editBrand(@RequestBody Brand brand){
    brandService.saveBrand(brand);
    return brand;
}
...
}

web.xml web.xml中

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">


    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
</web-app>

web.xml is referencing WEB-INF/dispatcher-servlet.xml, which has the following content web.xml引用了WEB-INF / dispatcher-servlet.xml,其中包含以下内容

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">

<context:component-scan base-package="com.acme.web.controller"/>


<!-- Data Source -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <!-- Production Environment -->
    <property name="driverClass" value="org.postgresql.Driver"/>
    <property name="jdbcUrl" value="jdbc:postgresql://x.x.x.xx/mydb"/>
    <property name="user" value="myuser"/>
    <property name="password" value="mypass" />

    <!-- c3p0 properties -->

    <property name="acquireIncrement" value="3"/>
    <property name="maxIdleTime" value="600"/><!-- seconds -->
    <property name="minPoolSize" value="3"/>
    <property name="maxPoolSize" value="6"/>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="packagesToScan" value="com.acme.model"/>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.hbm2ddl.auto">validate</prop>
            <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
            <prop key="hibernate.show_sql">false</prop>
        </props>
    </property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
    <property name="nestedTransactionAllowed" value="true"/>
</bean>
<tx:annotation-driven/>


<!-- scan for Spring MVC components -->
<mvc:annotation-driven/>



</beans>

catalina.out logs are the following (loglevel = INFO) catalina.out日志如下(loglevel = INFO)

    26-Jan-2015 13:10:41.459 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
26-Jan-2015 13:10:41.521 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
26-Jan-2015 13:10:41.524 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
26-Jan-2015 13:10:41.525 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
26-Jan-2015 13:10:41.526 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 2574 ms
26-Jan-2015 13:10:41.596 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
26-Jan-2015 13:10:41.601 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.3
26-Jan-2015 13:10:41.680 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive /home/me/apache-tomcat-8.0.3/webapps/ACME.war
26-Jan-2015 13:10:41.713 WARNING [localhost-startStop-1] org.apache.catalina.startup.SetContextPropertiesRule.begin [SetContextPropertiesRule]{Context} Setting property 'antiJARLocking' to 'true' did not find a matching property.
26-Jan-2015 13:10:47.897 INFO [localhost-startStop-1] org.apache.catalina.util.SessionIdGenerator.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [112] milliseconds.
2015-01-26 13:10:48,187 INFO  [localhost-startStop-1] servlet.FrameworkServlet (FrameworkServlet.java:484) - FrameworkServlet 'dispatcher': initialization started
2015-01-26 13:10:48,218 INFO  [localhost-startStop-1] support.AbstractApplicationContext (AbstractApplicationContext.java:510) - Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Mon Jan 26 13:10:48 GMT 2015]; root of context hierarchy
2015-01-26 13:10:48,274 INFO  [localhost-startStop-1] xml.XmlBeanDefinitionReader (XmlBeanDefinitionReader.java:317) - Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]
2015-01-26 13:10:49,172 INFO  [localhost-startStop-1] log.MLog (MLog.java:92) - MLog clients using log4j logging.
2015-01-26 13:10:49,206 INFO  [localhost-startStop-1] c3p0.C3P0Registry (C3P0Registry.java:216) - Initializing c3p0-0.9.2.1 [built 20-March-2013 10:47:27 +0000; debug? true; trace: 10]
26-Jan-2015 13:10:49.604 INFO [localhost-startStop-1] org.hibernate.annotations.common.reflection.java.JavaReflectionManager.<clinit> HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
26-Jan-2015 13:10:49.620 INFO [localhost-startStop-1] org.hibernate.Version.logVersion HHH000412: Hibernate Core {4.3.6.Final}
26-Jan-2015 13:10:49.625 INFO [localhost-startStop-1] org.hibernate.cfg.Environment.<clinit> HHH000206: hibernate.properties not found
26-Jan-2015 13:10:49.629 INFO [localhost-startStop-1] org.hibernate.cfg.Environment.buildBytecodeProvider HHH000021: Bytecode provider name : javassist
2015-01-26 13:10:50,015 INFO  [localhost-startStop-1] impl.AbstractPoolBackedDataSource (AbstractPoolBackedDataSource.java:522) - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hge2vb97an867f5dlj3r|2341b2f0, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> org.postgresql.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge2vb97an867f5dlj3r|2341b2f0, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:postgresql://xx.xx.xx.xx/mydb, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 600, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 6, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
26-Jan-2015 13:10:52.102 INFO [localhost-startStop-1] org.hibernate.dialect.Dialect.<init> HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
26-Jan-2015 13:10:52.123 INFO [localhost-startStop-1] org.hibernate.engine.jdbc.internal.LobCreatorBuilder.useContextualLobCreation HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
26-Jan-2015 13:10:52.208 INFO [localhost-startStop-1] org.hibernate.engine.transaction.internal.TransactionFactoryInitiator.initiateService HHH000399: Using default transaction strategy (direct JDBC transactions)
26-Jan-2015 13:10:52.222 INFO [localhost-startStop-1] org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory.<init> HHH000397: Using ASTQueryTranslatorFactory
26-Jan-2015 13:10:52.487 INFO [localhost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaValidator.validate HHH000229: Running schema validator
26-Jan-2015 13:10:52.487 INFO [localhost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaValidator.validate HHH000102: Fetching database metadata
2015-01-26 13:10:52,574 INFO  [localhost-startStop-1] hibernate4.HibernateTransactionManager (HibernateTransactionManager.java:360) - Using DataSource [com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hge2vb97an867f5dlj3r|2341b2f0, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> org.postgresql.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge2vb97an867f5dlj3r|2341b2f0, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:postgresql://xx.xx.xx.xx/mydb, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 600, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 6, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]] of Hibernate SessionFactory for HibernateTransactionManager
2015-01-26 13:10:53,555 INFO  [localhost-startStop-1] annotation.RequestMappingHandlerAdapter (RequestMappingHandlerAdapter.java:518) - Looking for @ControllerAdvice: WebApplicationContext for namespace 'dispatcher-servlet': startup date [Mon Jan 26 13:10:48 GMT 2015]; root of context hierarchy
2015-01-26 13:10:53,604 INFO  [localhost-startStop-1] annotation.RequestMappingHandlerAdapter (RequestMappingHandlerAdapter.java:518) - Looking for @ControllerAdvice: WebApplicationContext for namespace 'dispatcher-servlet': startup date [Mon Jan 26 13:10:48 GMT 2015]; root of context hierarchy
2015-01-26 13:10:53,670 WARN  [localhost-startStop-1] view.ContentNegotiatingViewResolver (ContentNegotiatingViewResolver.java:278) - Did not find any ViewResolvers to delegate to; please configure them using the 'viewResolvers' property on the ContentNegotiatingViewResolver
2015-01-26 13:10:53,701 INFO  [localhost-startStop-1] servlet.FrameworkServlet (FrameworkServlet.java:503) - FrameworkServlet 'dispatcher': initialization completed in 5512 ms
26-Jan-2015 13:10:54.334 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
26-Jan-2015 13:10:54.339 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
26-Jan-2015 13:10:54.344 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 12817 ms

Now if I deploy my application through Eclipse WTP, the mappings are picked up and the application works correctly. 现在,如果我通过Eclipse WTP部署应用程序,则将获取映射,并且该应用程序可以正常工作。 However, when I deploy the application in a "plain" Tomcat 8 container, the mappings are not picked up. 但是,当我在“普通的” Tomcat 8容器中部署应用程序时,不会拾取映射。

Note that the runtime package of Tomcat is exactly the same, the only difference is that once I used it from within Eclipse and the other Libs and classes deployed in WEB-INF are the same, so I suspect this has to do with some settings being customized by Eclipse, but I couldn't find any relevant difference. 请注意,Tomcat的运行时程序包是完全相同的,唯一的区别是,一旦从Eclipse中使用了它,并且WEB-INF中部署的其他Lib和类都相同,因此我怀疑这与某些设置有关由Eclipse定制,但我找不到任何相关的区别。

Would you have any idea? 你有什么主意吗? Thank you. 谢谢。

is your controller in another module? 您的控制器在另一个模块中吗? maybe eclipse it deploying it as classes and when you make war file it is not in current classes folder any more? 也许将它作为类部署而使其黯然失色,而在制作war文件时,它不再位于当前类文件夹中了吗?

ps: i think it was problem with resources. ps:我认为这是资源问题。 can not find any reason why it can be the cause with classes. 找不到任何原因可以成为类的原因。 anyway :D 无论如何:D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行独立 jar 时没有选择 arcgis 运行时库? - arcgis runtime libraries not being picked up when running standalone jar? 为什么在声明活动文件时没有将我的主要功能收起? - Why isn't my main function being picked up in my activity file when its declared? 通过WTP将依赖项目部署到Tomcat - Deploying Dependent Projects to Tomcat via WTP 我的Spring SecurityConfig没有被提取 - My Spring SecurityConfig is not being picked up 我的基于Spring的Restful Web服务在部署到独立的tomcat而不是Eclipse的Tomcat时给出404 - My Spring based Restful webservice gives 404 when deploy to standalone tomcat instead of Eclipse's Tomcat 是否可以设置Eclipse WTP来部署WAR,而不是在目标目录上进行复制? - Is it possible to set up Eclipse WTP for deploying WARs instead of copying over the target directory? 战争在本地独立的tomcat 7(无月食)上运行良好,上传到ec2时不起作用 - War works fine on local standalone tomcat 7 (no eclipse), does not work when uploaded to ec2 Spring MVC WebAPP可在Eclipse中运行,但在独立的Tomcat中部署时会生成异常 - Spring mvc webapp works in eclipse but generates an exception when deployed in standalone tomcat eclipse,wtp和tomcat的源文件夹配置 - eclipse, wtp and tomcat configuration for source folder eclipse 中的 Tomcat7 作为 WTP 项目未启动 - Tomcat7 in eclipse as WTP project not starting
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM