不知道是哪里问题,刚接触这东西。不知道配置是否有问题。下面贴出来配置,各位帮看看:
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