技术:java8 +spring 5.0.2.RELEASE
运行环境:IDEA 15.2 + jdk8 + windows 10
demo功能:提供一个spring 核心组件 bean demo
https://gitee.com/youlixishi/demo-world/tree/master/src/spring/spring-context
package com.demoworld;
import com.demoworld.hello.MessagePrinter;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/**
* Created by francis on 2017/12/11.
*/
@Configuration
@ComponentScan
public class Startup {
public static void main(String[] args) {
ApplicationContext context = new AnnotationConfigApplicationContext(Startup.class);
MessagePrinter printer = context.getBean(MessagePrinter.class);
printer.printMessage();
}
}
package com.demoworld.hello;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Created by francis on 2017/12/11.
*/
@Service
public class MessagePrinter {
final private MessageService service;
@Autowired
public MessagePrinter(MessageService service) {
this.service = service;
}
public void printMessage() {
System.out.println(this.service.getMessage());
}
}
package com.demoworld.hello;
/**
* Created by francis on 2017/12/11.
*/
public interface IMessageService {
String getMessage();
}
package com.demoworld.hello;
import org.springframework.stereotype.Component;
/**
* Created by francis on 2017/12/11.
*/
@Component
public class MessageService implements IMessageService {
public String getMessage() {
return "这个是啥";
}
}
欢迎添加微信,互相学习↑↑↑ -_-
白老虎
programming is not only to solve problems, ways to think
grafana 级连 菜单 templating (variables) 配置
rocketmq 集群搭建 (2master + 2slave + 2namesrv)
AI 机器人 抓取 微信 聊天中的 百度网盘 分享地址和密码