求助,整合jersey+spring+jpa+springmvc jersey的scan 扫描无法进入controller

babalaba80 2017-05-26 10:08:11
我现在在整合jersey+spring+jpa+springmvc
jersey的scan 扫描可以进restful 接口可以通过地址栏访问。
springmvc的controller怎样都进不去。看不出原因来。

附上spring-mvc.xml ,applicationContext.xml , web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- 查找最新的schemaLocation 访问 http://www.springframework.org/schema/ -->
<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:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<!-- 防止@ResponseBody中文乱码 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<bean
class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<bean class="org.springframework.http.MediaType">
<constructor-arg index="0" value="text" />
<constructor-arg index="1" value="plain" />
<constructor-arg index="2" value="UTF-8" />
</bean>
</list>
</property>
</bean>
</list>
</property>
</bean>

<!--<mvc:default-servlet-handler/>-->
<!-- 静态资源文件,不会被Spring MVC拦截 -->
<mvc:resources location="../../resources/spring" mapping="/resources/**"/>
<!-- 启用MVC注解 -->
<mvc:annotation-driven />
<!-- 指定Sping组件扫描的基本包路径 -->
<context:component-scan base-package="org1.coding.demo.springmvc.*" >
<!-- 这里只扫描Controller,不可重复加载Service -->
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

<!-- JSP视图解析器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
<property name="order" value="1" />
</bean>
</beans>


<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd

http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">

<context:component-scan base-package="org.codingpedia.demo.rest.*" />

<!-- ************ JPA configuration *********** -->
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="transactionManagerLegacy" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactoryLegacy" />
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath:config/persistence-demo.xml" />
<property name="persistenceUnitName" value="demoRestPersistence" />
<property name="dataSource" ref="restDemoDS" />
<property name="packagesToScan" value="org.codingpedia.demo.*" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
</bean>
</property>
</bean>
<bean id="entityManagerFactoryLegacy" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath:config/persistence-demo.xml" />
<property name="persistenceUnitName" value="demoRestPersistenceLegacy" />
<property name="dataSource" ref="restDemoLegacyDS" />
<property name="packagesToScan" value="org.codingpedia.demo.*" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
</bean>
</property>
</bean>

<bean id="podcastDao" class="org.codingpedia.demo.rest.dao.PodcastDaoJPA2Impl"/>
<bean id="podcastService" class="org.codingpedia.demo.rest.service.PodcastServiceDbAccessImpl" />
<bean id="podcastsResource" class="org.codingpedia.demo.rest.resource.PodcastsResource" />
<bean id="podcastLegacyResource" class="org.codingpedia.demo.rest.resource.PodcastLegacyResource" />

<bean id="restDemoDS" class="org.springframework.jndi.JndiObjectFactoryBean" scope="singleton">
<property name="jndiName" value="java:comp/env/jdbc/restDemoDB" />
<property name="resourceRef" value="true" />
</bean>
<bean id="restDemoLegacyDS" class="org.springframework.jndi.JndiObjectFactoryBean" scope="singleton">
<property name="jndiName" value="java:comp/env/jdbc/restDemoLegacyDB" />
<property name="resourceRef" value="true" />
</bean>
</beans>


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>Demo - Restful Web Application</display-name>
<!-- Spring Application Context Listener Start -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- Spring Application Context Listener End -->

<!-- Spring MVC Config Start -->
<servlet>
<servlet-name>Spring_MVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Spring_MVC</servlet-name>
<!-- Filter all resources -->
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- Spring MVC Config End -->

<!--jersey servlet begin-->
<!--<servlet>-->
<!--<servlet-name>jersey-serlvet</servlet-name>-->
<!--<servlet-class>-->
<!--org.glassfish.jersey.servlet.ServletContainer-->
<!--</servlet-class>-->
<!--<init-param>-->
<!--<param-name>javax.ws.rs.Application</param-name>-->
<!--<param-value>org.codingpedia.demo.rest.RestDemoJaxRsApplication</param-value> -->
<!--</init-param> -->
<!--<load-on-startup>1</load-on-startup>-->
<!--</servlet>-->
<!---->
<!--<servlet-mapping>-->
<!--<servlet-name>jersey-serlvet</servlet-name>-->
<!--<url-pattern>/*</url-pattern>-->
<!--</servlet-mapping>-->
<!--jersey servlet end-->

<resource-ref>
<description>Database resource for rest demo web application </description>
<res-ref-name>jdbc/restDemoDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
<description>Database resource for legacy system of demo rest web application </description>
<res-ref-name>jdbc/restDemoLegacyDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

<!-- Spring 编码过滤器 start -->
<filter>
<filter-name>characterEncoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring 编码过滤器 End -->
<!-- 隐藏的HttpMethod方法过滤器,表单提交中需要携带一个name=_method的隐藏域,value=put或者delete -->
<filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HiddenHttpMethodFilter</filter-name>
<servlet-name>SpringMVC</servlet-name>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
...全文
157 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
meijiong80 2017-05-31
  • 打赏
  • 举报
回复
找到原因。自己结了。jersey和springmvc不可以共用同一个url-pattern
babalaba80 2017-05-26
  • 打赏
  • 举报
回复
自己占楼顶个,另现在注释掉可以访问的jersey。单独地址栏访问spring mvc也无法进入。后台报错 o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/restfulpro/userowUser] in DispatcherServlet with name 'Spring_MVC'

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧