1、新建RunnableFactoryBean

 package com.spring4.pojo;

 import org.springframework.beans.factory.FactoryBean;

 /**
* Created by liuya
*
* @author User: liuya
* Date: 2018/5/3
* Time: 23:31
* projectName:spring4
*/
public class RunnableFactoryBean implements FactoryBean<Runnable> { /**
* 获取FactoryBean获取的实例对象
*
* @return Runnable
* @throws Exception
*/
@Override
public Runnable getObject() throws Exception {
return () -> {
};
} /**
* 创建什么类型的对象
*
* @return Class<?>
*/
@Override
public Class<?> getObjectType() {
return Runnable.class;
} /**
* 是不是单例的
*
* @return
*/
@Override
public boolean isSingleton() {
return true;
}
}

2、加载到Myconfig中

 package com.spring4.conf;

 import com.spring4.pojo.RunnableFactoryBean;
import com.spring4.pojo.User;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope; /**
* Created by liuya
*
* @author : liuya
* Date: 2018/5/2
* Time: 23:50
* projectName:spring4
* 配置类
*/ @Configuration
public class SpringConf { /**
* 配置bean 写一个方法,返回bean
* <p>
* 指定名字,默认是方法名字
*/
@Bean(name = "getUser")
/**
* 修改为非单例模式,创建的对象就是不一样的了
*
*/
@Scope(value = "prototype")
public User getUser() {
User user = new User();
user.setAge(29);
user.setUserName("王圆圆");
user.setPassWord("1110000"); return user;
} @Bean
public RunnableFactoryBean createRunnableFactoryBean() {
RunnableFactoryBean runnableFactoryBean = new RunnableFactoryBean(); return runnableFactoryBean; } }

3、方法加入Application测试

 package com.study.spring;

 import com.spring4.conf.SpringConf;
import com.spring4.pojo.RunnableFactoryBean;
import com.spring4.pojo.User;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import java.io.IOException;
import java.util.List; /**
* @author liuyang
*/
@SpringBootApplication
public class Spring4Application { public static void main(String[] args) {
// 通过Java配置来实例化Spring容器
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConf.class); // 在Spring容器中获取Bean对象
User user = context.getBean(User.class); //根据名字获取(默认是根据方法名字获取)
Object user2 = context.getBean("getUser"); System.out.println(user.getUserName() + ", " + user.getAge() + ", " + user.getPassWord());
System.out.println(user2.toString() + ", ");
String list = user2.toString();
String[] ont = list.split(",");
for (int i = 0; i < ont.length; i++) {
System.out.println(ont[i]);
} RunnableFactoryBean runnableFactoryBean = context.getBean(RunnableFactoryBean.class); try {
System.out.println("createRunnableFactoryBean :"+runnableFactoryBean);
} catch (Exception e) {
e.printStackTrace();
} // 销毁该容器
context.destroy();
}
}

IntelliJ IDEA 2017版 Spring5 的RunnableFactoryBean配置的更多相关文章

  1. IntelliJ IDEA 2017版 Spring5最基本的bean例子创建

    一.简述         SpringBoot是基于spring框架之上的快速开发的框架.Spring4核心就是容器,容器提供了对bean的装配和管理.       spring依赖加载:       ...

  2. IntelliJ IDEA 2017版 SpringBoot的核心配置详解

    Spring Boot的核心   (1)Spring Boot的项目一般都会有*Application的入口类,入口类中会有main方法,这是一个标准的Java应用程序的入口方法.  (2)@Spri ...

  3. IntelliJ IDEA 2017版 Spring5 java.lang.NoSuchMethodError: org.springframework.boot.SpringApplication.<init>([Ljava/lang/Object;)V

    错误是java.lang.NoSuchMethodError: org.springframework.boot.SpringApplication.<init>([Ljava/lang/ ...

  4. IntelliJ IDEA 2017版 spring-boot加载jsp配置详解(详细图文实例)

    一.创建项目 (File--->New-->Project) 2.项目配置内容 3.选择配置项目的Group包名,Artifact项目名称 4.选择项目类型为web类型 5.创建成功,点击 ...

  5. IntelliJ IDEA 2017版 spring-boot2.0.4的yml配置使用

    一.必须配置字端两个 server: port: 8080 servlet: context-path: /demo 二.两种mvc转换springboot,一种是注解,一种就是.yml或proper ...

  6. IntelliJ IDEA 2017版 SpringBoot的关闭自动配置和自定义Banner

    一.关闭自动配置 在jar包下找下边的名字    设置关闭自动配置jar    多个的时候配置       二.自定义Banner   (1)网站搜索一个图案.网址:http://patorjk.co ...

  7. IntelliJ IDEA 2017版 spring-boot修改端口号配置把端口号改为8081

    1.修改端口号主要是通过配置文件修改.如图: 完整版配置 ######################################################## ###server 配置信息 ...

  8. IntelliJ IDEA 2017版 spring-boot2.0.2 自动配置Condition

    描述: 编译器修改参数      -Dfile.encoding=GBK     -Dstr.encoding=GBK Condition位置: 某一个类或注解存在的时候,装配,否则不装配 相关代码: ...

  9. IntelliJ IDEA 2017版 spring-boot 2.0.5 邮件发送简单实例 (三)

    一.搭建SpringBoot项目 详见此文:https://www.cnblogs.com/liuyangfirst/p/8298588.html 注意: 需要添加mail依赖的包,同时还添加了lom ...

随机推荐

  1. ln: operation not permitted

    ln: operation not permitted 在挂载的磁盘上建立软链接提示没有操作权限 例如: ln -s aa bb1ln:aa operation not permitted------ ...

  2. ERROR: APK path is not specified for

    1. 打开project structure 2.设置outpath路径 最好为绝对路径 点击确定  重新编译即可. Note: Android Studio版本使用

  3. 解决Eclipse添加新server时无法选择Tomcat7的问题

    在Eclipse中创建了一个Web工程后,需要将该工程部署到Tomcat中进行发布.有时就会遇到在New Server对话框中选择了Tomcat 6/7后却无法单击“Next”按钮的问题,如下图所示: ...

  4. tomcat/eclipse提速[z]

    在使用Eclipse开发项目过程中,一度使Eclipse陷入瘫痪状态,Tomcat启动项目时也异常缓慢,增加了超时限制并没有用,有时候项目根本运行不起来,简直让人崩溃,可能我电脑内存小(4G),配置低 ...

  5. css布局之头尾固定中间高度自适应

    被这个问题困扰了很久.大神别鄙视我,我是搞后台开发的....试过了很多方法,比如设定高度100%.同事用的js计算高度,我对js设置的方式一直觉得不够好,尽管设置高度为100%的方式更差,直到发现了一 ...

  6. vue2.0插件

    1.better-scroll 参考网址:https://ustbhuangyi.github.io/better-scroll/doc/zh-hans/ better-scroll 是什么 firs ...

  7. DevExpress如何实现皮肤的添加及本地化

    DevExpress.XtraBars.Helpers.SkinHelper类允许您填充现有RibbonGalleryBarItem或任意菜单(PopupMenu或BarSubItem)项目对应的De ...

  8. c#特性attribute:

    特性是被编译到metadata中,  是提供给反射用的. 特性attribute:1 什么是attribute,和注释有什么区别 2 声明和使用attribute3 使用attribute完成扩展4 ...

  9. 2Y - sort

    给你n个整数,请按从大到小的顺序输出其中前m大的数.  Input 每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且都处于区间[-5000 ...

  10. Linux系统和性能监控之CPU篇

    Linux系统和性能监控之CPU篇 性能优化就是找到系统处理中的瓶颈以及去除这些的过程.本文由sanotes.net站长tonnyom在2009年8月翻译自Linux System and Perfo ...