在我的Spring MVC +休眠+標註的項目,我有這三類需要了解spring mvc項目中的autowiring bean嗎?
UserServiceImpl.java
@Service("userService")
public class UserServiceImpl implements UserService {
@Autowired
private UserDAO userDAO;
//other codes
}
UserDAOImpl.java
@Repository("userDAO")
public class UserDAOImpl implements UserDAO {
@Autowired
private SessionFactory sessionFactory;
//other codes
}
RegistrationController.java
@Controller
@RequestMapping("/registration.htm")
public class RegistrationController {
@Autowired
private UserService userService;
//other codes
}
在我調度-servlet.xml中我加入以下
<context:annotation-config />
<context:component-scan base-package="com.alw.controllers,com.alw.DAOs,com.alw.services" />
和
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
當我跑我得到了以下的例外項目:
Error creating bean with name 'registrationController':
Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: private com.alw.services.UserService
com.alw.controllers.RegistrationController.userService;
AND
Error creating bean with name 'sessionFactory' defined in ServletContext resource
[/WEB-INF/dispatcher-servlet.xml]:
Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError:
org/apache/commons/pool/impl/GenericObjectPool
可能有人指出我在哪裏缺失?
今天已經過去了一整天。
編輯:
我添加了commons.pool但沒有結果。
我有這些例外。
Error creating bean with name 'registrationController':
Error creating bean with name 'userService':
Error creating bean with name 'userDAO':
Error creating bean with name 'sessionFactory' defined in ServletContext
resource [/WEB-INF/dispatcher-servlet.xml]:
Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError:
Could not initialize class org.hibernate.cfg.AnnotationConfiguration
感謝....
關掉你的CAPS LOCK!它看起來很像你!它被認爲是在互聯網上的RudE! – duffymo