當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring配置Bean的方式
生活随笔
收集整理的這篇文章主要介紹了
Spring配置Bean的方式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
配置Bean
基于XML配置Bean
基于注解配置Bean
基于Java類配置Bean
基于XML配置
ApplicationContext.xml <bean id=“loginUserDao” class=“com.chinalife.dao.impl.LoginUserDaoImpl” lazy-init=“true” init-method=“myInit” destroy-method=“myDestroy” scope=“prototype”> …… </bean>簡寫
<bean id="beanFactroy" class="com.stonegeek.service.impl.BeanFactroyImpl" />基于注解配置
在具體的類中,使用注解
@Controller,控制器類
@Service,業務邏輯類
@Repository,DAO類
@Component,普通的Spring Bean類
基于Java類配置
代碼
@Configuration public class Conf { @Scope(“prototype”) @Bean(“loginUserDao”) public LoginUserDao loginUserDao() { return new LoginUserDao(); } }推薦
注解的方式,配置Bean,使用方便
總結
以上是生活随笔為你收集整理的Spring配置Bean的方式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring整合Hibernate
- 下一篇: Spring获取属性配置