Rinoux 2016-04-29 02:16 采纳率: 0%
浏览 1419
已结题

@autowire在非jersey服务类中不注入(spring+jersey_mybatis)

使用@autowired可以在jersey的服务类中注入,但是在其它类中就无法注入,显示@autowired的对象为空。

spring.xml如下:

 <?xml version="1.0" encoding="UTF-8"?>
<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"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd">

    <!-- 自动将包前缀为cc.rinoux.server.*的包中以@Service@Component@Controller标注的类注册为bean
            在jersey中,ResourceConfig的实现类将服务所在的包注册(***packages("cc.rinoux.server.service");***)
            相当于为包中类添加了@Component注解 -->
    <context:component-scan base-package="cc.rinoux.server.*" />    
        <context:component-scan base-package="cc.rinoux.server.mina.handler" /> 
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> 
        <!-- 本地数据库配置 -->
 略

    </bean>
    <!-- sqlSessionFactoryBean相当于sqlSrssionFactoryBuilder,在mybatis-spring用法中,
    无需直接使用bean或sqlsessionFactory,session工厂将会被注入到MapperFactoryBean或
    其它扩展了sqlSessionSupport的DAO
     -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
      <property name="dataSource" ref="dataSource" />
      <property name="configLocation" value="classpath:mybatis.xml"></property>
      <!-- 将mapper包中所有文件和XXXmapper.xml文件对应起来 -->
      <property name="mapperLocations" value="classpath:mapper/*.xml" />
    </bean>
    <!-- dao 自动扫描mapper中的DAO,并注册为bean-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
      <property name="basePackage" value="cc.rinoux.server.mapper" />
    </bean>
    <!--  -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
      <property name="dataSource" ref="dataSource"/>
    </bean>
    <!-- 注解方式配置事务 -->
    <tx:annotation-driven transaction-manager="transactionManager" />


</beans>

  • 写回答

1条回答 默认 最新

  • imaging123 2016-04-29 08:51
    关注

    报的什么错?贴出来看看

    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程