日期:2014-05-17  浏览次数:20621 次

spring3 注解注入为空

@Service
@Transactional
public class LoginBo {
@Autowired
private HibDao hibDao;

public Object queryById(Class cls,String id){
return hibDao.queryById(cls, id);
}
public UserEntity queryByName(String userName){
String hsql = "from UserEntity t where t.userName="+userName;
List li = hibDao.query(hsql);
return (UserEntity) li.get(0);
}

}


<!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 -->
<context:component-scan base-package="com.bo,com.dao" />

------解决方案--------------------
为何不见你的SessionFactory 这个也需要注入。
------解决方案--------------------
jar包引入对不对
------解决方案--------------------
commons-logging-1.1.1  jar
spring-context-support-3.0.4.RELEASE  jar
------解决方案--------------------
引用:
Quote: 引用:

commons-logging-1.1.1  jar
spring-context-support-3.0.4.RELEASE  jar

这两个jar有的

既然用的注解,那把
<bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

改成这样:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">