spring 泛型注入遇到的问题,求助一下(急)。
首先先看看我的配置
spring-mybatis
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->
<property name="mapperLocations">
<list>
<value>classpath:com/ccqws/*/persistence/*.xml</value>
</list>
</property>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.ccqws.mapper.base,com.ccqws.mapper.manager,com.ccqws.mapper.user" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
sping-main
<!-- 扫描包 -->
<context:component-scan base-package="com.ccqws" />
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager">
<mvc:message-converters register-defaults="true">
<!-- 将StringHttpMessageConverter的默认编码设为UTF-8 -->
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg value="UTF-8" />
</bean>
<!-- 将Jackson2HttpMessageConverter的默认格式化输出设为true -->
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="prettyPrint" value="true" />
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<!-- REST中根据URL后缀自动判定Content-Type及相应的View -->
<!-- 默认是json视图, 当后缀是xxx.xml时, 表示返回的是xml, 注意实体需要加上@XmlRootElement注解 -->
<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="ignoreAcceptHeader" value="true" />
<property name="defaultContentType" value="application/json" />
<property name="mediaTypes">
<value>
json=application/json
xml=application/xml
</value>
</property>
</bean>
sping-tx
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="set*" read-only="true" />
<tx:method name="query*" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="load*" read-only="true" />
<tx:method name="count*" read-only="true" />
<tx:method name="select*" read-only="true" />
<tx:method name="save*" rollback-for="Exception" />
<tx:method name="add*" rollback-for="Exception" />
<tx:method name="insert*" rollback-for="Exception" />
<tx:method name="update*" rollback-for="Exception" />
<tx:method name="delete*" rollback-for="Exception" />
<tx:method name="merage*" rollback-for="Exception" />
<tx:method name="create*" rollback-for="Exception" />
<tx:method name="*" rollback-for="Exception" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="busiOperation" expression="execution(* com.ccqws.service.*.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="busiOperation" />
</aop:config>
以上是我的配置文件,下面是我的代码
这是我的controller
@RestController
@RequestMapping("test")
public class TestController {
@Resource
private CcqUserService userService;
/**
* 测试方法
*
* @param name
* @return
*/
@RequestMapping(method = { RequestMethod.GET }, value = "/TestEnt/{id}/{name}")
public MessageEnt getMessage(@PathVariable String id, @PathVariable String name) {
TestEnt t = new TestEnt();
t.setId(id);
t.setName(name);
MessageEnt ent = new MessageEnt();
return ent;
}
@RequestMapping(method = RequestMethod.POST, value = "/employee2/{id}/{name}")
@ResponseBody
public String addMessage(@PathVariable String id, @PathVariable String name) {
return "hello:新增" + id + "name:" + name;
}
@RequestMapping(method = RequestMethod.PUT, value = "/employee3/{id}/{name}")
@ResponseBody
public String setMessage(@PathVariable String id, @PathVariable String name) {
return "hello:更新" + id + "name:" + name;
}
@RequestMapping(method = RequestMethod.DELETE, value = "/employee4/{id}/{name}")
@ResponseBody
public String delMessage(@PathVariable String id, @PathVariable String name) {
return "hello:删除" + id + "name:" + name;
}
这是我的service
@Service
public class CcqUserService extends BaseService<CcqUserMapper, CcqUser> {
@Autowired
public CcqInterfaceAuthorityMapper ccqInterfaceAuthorityMapper;
@Autowired
public CcqUserInterfacePriceMapper ccqUserInterfacePriceMapper;
@Autowired
public CcqChargeClientMapper ccqChargeClientMapper;
@Autowired
public CcqUserInterfaceLimitMapper ccqUserInterfaceLimitMapper;
public CcqUser selectByUser(CcqUser user) {
return this.dao.selectByUser(user);
}
/**
* 验证当前用户的接口调用权限
*
* @param user
* @param methodName
* @return
*/
public String checkAuthority(CcqUser user, String methodName) {
String mess = "";
if ((user != null) && (methodName != null)) {
Map<String, String> param = new HashMap<String, String>();
param.put("user_name", user.getUserName());
param.put("inter_name", methodName);
int num = this.ccqInterfaceAuthorityMapper.checkAuthority(param);
if (num == 0) {
return PublicProperties.getValueByKey("error_206");
}
// 预付费用户,验证余额是否够调用该接口
String msg = this.isMoneyEnough(user, methodName);
if (null != msg) {
return msg;
}
// 验证接口条数限制
msg = this.isInterfaceInvokedEnough(user, methodName);
if (null != msg) {
return msg;
}
} else {
return PublicProperties.getValueByKey("error_206");
}
return mess;
}
}
这是我的DAO
public interface CcqUserMapper extends BaseMapper<CcqUser> {
CcqUser selectByUser(CcqUser user);
}
现在的问题就是我启动的时候提示我泛型中的DAO 无法注入
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ccqUserService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected com.ccqws.mapper.base.BaseMapper com.ccqws.service.base.BaseService.dao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.ccqws.mapper.base.BaseMapper] 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)
请大神帮我,瞅瞅。 眼镜都快看瞎了。 BaseMapper 和 BaseService 稍后追加上。