框架结构如下:
@Controller
public class LoginAction{
@Autowired
private LoginService loginService;
@Service
public class LoginServiceImpl implements LoginService {
@Autowired
private RoleDao roleDao;
@Repository
public class RoleDaoImpl implements RoleDao {
@Autowired
private SessionFactory sessionFactory;
@Autowired
private BaseDao baseDao;
@Repository
public class BaseDaoImpl implements BaseDao{
@Autowired
private SessionFactory sessionFactory;
问题出现, 假如我不使用baseDao 直接在roleDao使用sessionFactory进行查询 没有任何问题
[color=#FF0000]各层都会被正常装载,但是当我添加baseDao功能,在roleDao中加载baseDao进行方法调用时,就
出现了 Could not instantiate bean class [com.mvc.base.dao.impl.BaseDaoImpl]: Constructor threw exception; nested exception is java.lang.NullPointerException 的异常
<!--对web包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 -->
<context:component-scan base-package="com.mvc.java">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<context:component-scan base-package="com.mvc.base">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
包扫描问题我也考虑了 base package下只用dao层功能 ,我就疑问,框架各功能应该是正常的,因为有成功的例子,但是在装载其他包内的dao时却出现了无法注入的问题,实在无法找到问题,跪求大神指导
springMVC 注解注入 annotation
------解决方案--------------------
问一下设计 这个有必要么 BaseDaoImpl
俺自己练习的时候 有个base的接口 把一些通用的方法都写在里面 比如一些通用的增删改查
然后还有一些对应各个实体的 接口 里面只放一些实体各自对应的特殊方法 继承这个 base接口,当然了base接口里可以有一些泛型
最后再写一个实体的 serviceimpl 实现这个 实体接口就可以了
------解决方案--------------------
还是继承这个 base接口吧,想调用别的DAO,最好是放在业务层调,这样事务都好控制