基于 Java 的 bean 配置
来源:互联网 发布:java并发编程实战手册 编辑:程序博客网 时间:2024/05/21 17:37
一、声明
本测试没有使用任何xml代码
主要分 Dao、Service 层来写
为了容易阅读,文件名也相当清晰
二、代码
①DaoInterface
package test;public interface DaoInterface { void showDAO();}
②DaoImplements
package test;import org.springframework.stereotype.Component;@Componentpublic class DaoImplements implements DaoInterface { @Override public void showDAO() { System.out.println("DAO is playing Spring now"); }}
③ServiceInterface
package test;public interface ServiceInterface { void showService();}
④ServiceImplements
package test;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;@Componentpublic class ServiceImplements implements ServiceInterface { private DaoInterface mi; @Autowired public ServiceImplements(DaoInterface mi) { this.mi = mi; } @Override public void showService() { System.out.println("Service begin"); mi.showDAO(); System.out.println("Service end"); }}
⑤JavaConfiguration java配置取代xml配置
package test;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;@Configuration@ComponentScanpublic class JavaConfiguration {}
⑥SpringTest 测试类
package test;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(classes = JavaConfiguration.class)public class SpringTest { // @Autowired //①变量上面可以放@Autowired private ServiceInterface service; @Autowired // ②setter上面也可以放@Autowired public void setService(ServiceInterface service) { this.service = service; } @Test public void test() { service.showService(); }}
阅读全文
1 0
- 基于 Java 的 bean 配置
- Java Spring Tutorial -- 基于Bean的配置 @Configuration @Bean
- Bean 基于注解的配置
- IOC之基于Java类的配置Bean
- Spring中基于Java的配置@Configuration和@Bean用法
- Spring中基于Java的配置@Configuration和@Bean用法
- IOC之基于Java类的配置Bean
- Spring中基于Java的配置@Configuration和@Bean用法
- Spring中基于Java的配置@Configuration和@Bean用法
- Spring中基于Java的配置@Configuration和@Bean用法
- Spring中基于Java的配置@Configuration和@Bean用法
- Spring中基于Java的配置@Configuration和@Bean用法
- Spring中基于Java的配置@Configuration和@Bean用法
- Spring中基于Java的配置@Configuration和@Bean用法
- Spring中基于Java的配置@Configuration和@Bean用法
- Spring中基于Java的配置@Configuration和@Bean用法
- Spring中基于Java的配置@Configuration和@Bean用法
- Spring中基于Java的配置@Configuration和@Bean用法
- SpringMVC解析JSON请求数据
- Rsync安全配置&利用
- 强大的字符数组
- Jquery-选择器-简单的选择器
- linux -日期时间命令
- 基于 Java 的 bean 配置
- 一些Python库的安装
- Filter 过滤器
- 12.2 省选训练总结
- Android 用Retrofit进行网络获取数据,recyclerview进行展示在Fragment里,并存入到GreenDao数据库中
- ButterKnife注解框架
- Python之break和continue
- vim
- 【1701H1】【穆晨】【171203】连续第五十四天总结