spring 泛型注入遇到的问题,求助一下(急)。

wd308389182 2016-04-27 09:20:57
首先先看看我的配置

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 稍后追加上。
...全文
244 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wd308389182 2016-04-27
  • 打赏
  • 举报
回复
麻烦大婶们帮我定位, 谢谢。
wd308389182 2016-04-27
  • 打赏
  • 举报
回复
追加BaseMapper 和BaseService 这是BaseService package com.ccqws.service.base; import org.springframework.beans.factory.annotation.Autowired; import com.ccqws.entity.base.BaseEntity; import com.ccqws.mapper.base.BaseMapper; /** * 基本service * * @author 李朝阳 * */ public abstract class BaseService<D extends BaseMapper<T>, T extends BaseEntity> { @Autowired protected D dao; /** * 通过id查询 实体 * * @param id * id * @return 实体 */ public T selectById(Integer id) { return this.dao.selectByPrimaryKey(id); } /** * 插入 * * @param entity * 实体 * @return 操作了多少条 */ public Integer insert(T entity) { return this.dao.insert(entity); } /** * 通过id,修改实体 * * @param entity * 实体 * @return 操作了多少条数据 */ public Integer updateById(T entity) { return this.dao.updateByPrimaryKeySelective(entity); } /** * 通过id逻辑删除实体(操作del_flag字段设置为1) * * @param id * id * @return 提示信息 */ public Integer deleteById(Integer id) { return this.dao.deleteByPrimaryKey(id); } } 这是BaseMapper package com.ccqws.mapper.base; public interface BaseMapper<T> { /** * 根据主键删除 * * @param id * @return */ int deleteByPrimaryKey(Integer id); /** * 新增 * * @mbggenerated Tue Apr 26 09:46:53 CST 2016 */ int insert(T entity); /** * 根据字段插入数据 * * @mbggenerated Tue Apr 26 09:46:53 CST 2016 */ int insertSelective(T entity); /** * 根据主键查询数据 * * @mbggenerated Tue Apr 26 09:46:53 CST 2016 */ T selectByPrimaryKey(Integer id); /** * 根据字段更新数据 * * @param record * @return */ int updateByPrimaryKeySelective(T entity); /** * 更新全部字段 * * @mbggenerated Tue Apr 26 09:46:53 CST 2016 */ int updateByPrimaryKey(T entity); }
家里敷泥呀 2016-04-27
  • 打赏
  • 举报
回复
为什么没有看到@Repository注解?
  • 打赏
  • 举报
回复
在里边没看到get/set方法,不知道是没写还是没贴

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧