SSH下使用Spring注解自动注入bean

Spring注解的使用方法详见:http://www.ibm.com/developerworks/cn/java/j-lo-spring25-ioc/,这里在SSH框架下做一个例子。

首先导入相关包:spring-beans-3.0.4.RELEASE.jar(org.springframework.beans.factory.annotation.Autowired用来注入bean)、spring-context-3.0.4.RELEASE.jar(org.springframework.stereotype.Componet 、Service、Repository等用来定义bean)。

其次需要添加相关配置:applicationContext.xml

web.xml

使用Hibernate JPA定义User类:

Dao层:

Service层:

Action:

调试信息如下:

Hibernate: select hibernate_sequence.nextval from dual
Hibernate: insert into s_user (pwd, name, id) values (?, ?, ?)
2011-03-10 19:44:25,296 [http-8080-1] DEBUG [com.dao.Impl.UserDaoImpl] - save user:cuihaiyang
2011-03-10 19:44:25,296 [http-8080-1] DEBUG [com.service.Impl.UserManagerImpl] - add User:cuihaiyang

评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值