-1

弹簧配置:

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


<mybatis-spring:scan base-package="com.example.dao.**" />
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/schema15" />
    <property name="username" value="root" />
    <property name="password" value="password" />
</bean>
<bean id="sqlSessionFactoryBean"
    class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource"></property>
    <property name="configLocation"
        value="classpath:mybatis-config.xml">
    </property>
</bean>
</beans>

Mybatys 配置:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
   PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
   "http://mybatis.org/dtd/mybatis-3-config.dtd">

 <configuration>
  <settings>
    <setting name="cacheEnabled" value="true" />
    <setting name="lazyLoadingEnabled" value="true" />
    <setting name="multipleResultSetsEnabled" value="true" />
    <setting name="useColumnLabel" value="true" />
    <setting name="useGeneratedKeys" value="false" />
    <setting name="autoMappingBehavior" value="PARTIAL" />
    <setting name="defaultExecutorType" value="SIMPLE" />
    <setting name="defaultStatementTimeout" value="25" />
    <setting name="safeRowBoundsEnabled" value="false" />
    <setting name="mapUnderscoreToCamelCase" value="false" />
    <setting name="localCacheScope" value="SESSION" />
    <setting name="jdbcTypeForNull" value="OTHER" />
    <setting name="lazyLoadTriggerMethods"           value="equals,clone,hashCode,toString" />
  </settings>

<typeAliases>
    <typeAlias type="com.example.model.UserLogIn"
        alias="UserLogIn"></typeAlias>  
</typeAliases>

<mappers>
    <mapper resource="userlogin_mapper.xml" />      
</mappers>

</configuration>

服务弹簧配置:

<?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:sws="http://www.springframework.org/schema/web-services"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/web-services
   http://www.springframework.org/schema/web-services/web-services-2.0.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">


  <context:component-scan
     base-package="com.example.services,com.example.userlogin.schemas," />
   <sws:annotation-driven />

  <!-- Our test service bean -->
  <bean id="UserService"
  class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition"
  lazy-init="true">
  <property name="schemaCollection">
   <bean
   class="org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection">
      <property name="inline" value="true" />
      <property name="xsds">
        <list>
          <value>schemas/UserServiceOperations.xsd</value>
        </list>
       </property>
   </bean>
  </property>
  <property name="portTypeName" value="UserService" />
  <property name="serviceName" value="UserService" />
  <property name="locationUri" value="/endpoints" />
  </bean>
  </beans>

我有两个项目:dao 和 services。在 dao 中,我有一个用于 userLogin 的映射器,名为 IUserLoginDAO。我在 dao 项目中创建了一个 junit 测试类来测试方法和所有通过的测试。在服务中,我依赖于 dao 项目。在服务项目中,我有一个名为 UserServiceImpl 的类,我尝试使用 @Autowired 注入 IUserLoginDAO。当我在 tomcat 中部署服务项目时,出现以下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceEndpoints': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.example.services.UserService com.example.services.endpoints.UserServiceEndpoints.userService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.example.dao.IUserLoginDAO com.example.services.UserServiceImpl.userDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.example.dao.IUserLoginDAO] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

任何意见都非常感谢!谢谢!

4

1 回答 1

0

不确定 mybatis-spring scan 是否真的支持通配符。您是否尝试过明确定义映射器?

<bean id="userLoginDAO" class="org.mybatis.spring.mapper.MapperFactoryBean">
    <property name="mapperInterface" value="...myMapperInterface" />
    <property name="sqlSessionFactory" ref="sqlSessionFactoryBean" />
</bean>
于 2015-07-23T09:07:52.383 回答