Code Bye

Spring+jersey配置,javax.ws.rs.core.UriBuilder.uri方法异常

不知道是哪里问题,刚接触这东西。不知道配置是否有问题。下面贴出来配置,各位帮看看:
web.xml:

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/applicationContext.xml</param-value>
</context-param>
<!– Jersey Servlet 配置 –>
<servlet>
<servlet-name>Jersey Spring</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<!– 系统启动时扫描的包的路径 –>
<param-value>com.icontrol.resource</param-value>
</init-param>

</servlet>
<servlet-mapping>
<servlet-name>Jersey Spring</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

spring的配置:

<?xml version=”1.0″ encoding=”UTF-8″?>
<beans xmlns=”http://www.springframework.org/schema/beans”
    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-3.0.xsd”>
    
    <bean  class=”org.springframework.beans.factory.config.PropertyPlaceholderConfigurer”>
        <property name=”locations”>
            <value>classpath:/database.properties</value>
        </property>
    </bean>

    <bean id=”dataSource” class=”org.apache.commons.dbcp.BasicDataSource” destroy-method=”close”>
        <property name=”driverClassName” value=”${driver}”/>
        <property name=”url” value=”${url}”/>
        <property name=”username” value=”${username}”/>
        <property name=”password” value=”${password}”/>
        <property name=”maxActive” value=”${maxActive}”/>
        <property name=”maxIdle” value=”${maxIdle}”/>
<property name=”maxWait” value=”${maxWait}”></property>
    </bean>
    
    <bean id=”sqlSessionFactory” class=”org.mybatis.spring.SqlSessionFactoryBean”>
      <property name=”dataSource” ref=”dataSource” />
      <!– 指定sqlMapConfig总配置文件,订制的environment在spring容器中不在生效–>
      <property  name=”configLocation”  value=”classpath:mybatis-config.xml”/>
      <!–指定实体类映射文件,可以指定同时指定某一包以及子包下面的所有配置文件,mapperLocations和configLocation有一个即可,当需要为实体类指定别名时,可指定configLocation属性,再在mybatis总配置文件中采用mapper引入实体类映射文件 –>
   </bean> 

<!– 
    <bean id=”userDao” class=”com.icontrol.dao.UserDao”>
        <property name=”sqlSessionFactory” ref=”sqlSessionFactory”></property>
    </bean>
 –>
 
  <bean id=”userDao” class=”org.mybatis.spring.mapper.MapperFactoryBean”>
        <property name=”mapperInterface” value=”com.icontrol.dao.UserDao”></property>
        <property name=”sqlSessionFactory” ref=”sqlSessionFactory”></property>
    </bean>
 

<!– 服务bean –>

 <bean id=”userService” class=”com.icontrol.resource.UserResource”>  
   </bean>  

</beans>

具体log:
2013-7-9 14:33:07 com.sun.jersey.api.core.PackagesResourceConfig init
信息: Scanning for root resource and provider classes in the packages:
  com.icontrol.resource
2013-7-9 14:33:07 com.sun.jersey.api.core.ScanningResourceConfig logClasses
信息: Root resource classes found:
  class com.icontrol.resource.UserResource
2013-7-9 14:33:07 com.sun.jersey.api.core.ScanningResourceConfig init
信息: No provider classes found.
2013-7-9 14:33:07 com.sun.jersey.spi.spring.container.servlet.SpringServlet getContext
信息: Using default applicationContext
2013-7-9 14:33:07 com.sun.jersey.spi.spring.container.SpringComponentProviderFactory registerSpringBeans
信息: Registering Spring bean, userService, of type com.icontrol.resource.UserResource as a root resource class
2013-7-9 14:33:07 com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
信息: Initiating Jersey application, version “”Jersey: 1.9.1 09/14/2011 02:36 PM””
2013-7-9 14:33:07 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [Jersey Spring] in context with path [/icontrol] threw exception [Servlet execution threw an exception] with root cause
java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:671)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)

还有一点是:web.xml中的
<servlet-mapping>
<servlet-name>Jersey Spring</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

改为:
<servlet-mapping>
<servlet-name>Jersey Spring</servlet-name>
<url-pattern>/icontrol/*</url-pattern>
</servlet-mapping>
时jersey根本拦截不到,何故

好吧。也没人回答。这问题恶心了我一天!

找了一个示例,却成功了。看来是jar包问题了。还不知道具体在哪。继续找了

引用 4 楼 coocaobo 的回复:

问题解决了没有?

额,我都忘了怎么解决的了。好像是修改了资源包路径吧。
<context:annotation-config />
<context:component-scan base-package=”services”>
<context:exclude-filter type=”annotation”
expression=”org.springframework.stereotype.Service” />
</context:component-scan>

引用 5 楼 liuminsds 的回复:

肿么解决的??遇到这个问题了,纠结~求告知。。谢谢~~

额,我都忘了怎么解决的了。好像是修改了资源包路径吧。
<context:annotation-config />
<context:component-scan base-package=”services”>
<context:exclude-filter type=”annotation”
expression=”org.springframework.stereotype.Service” />
</context:component-scan>

我没有结合spring 为何报这个错  感觉像是jar包冲突的问题 又不知道是什么?求大神解答
导入jersey jar 包就不要再导入javax.ws.rs,会引发冲突

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Spring+jersey配置,javax.ws.rs.core.UriBuilder.uri方法异常