springboot11-创建非web工程实现方式1

注意:不需要添加web依赖

1、写service接口

2、写接口实现类

3、启动类

@SpringBootApplication
public class Springboot08Java1Application {

    public static void main(String[] args) {
        /*
        springboot程序启动后,返回值是,他是一个Spring容器
        它其实相当于原来的Spring容器中的启动容器ClasspathXmlApplicationContext
         */

        //获取Springboot容器
        ConfigurableApplicationContext applicationContext = SpringApplication.run(Springboot08Java1Application.class, args);

        //从spring容器中获取指定bean对象(service未指定名称,就用类首字母小写的名称)
        StudentService studentServiceImpl = (StudentService) applicationContext.getBean("studentServiceImpl");

        String s = studentServiceImpl.sayHello();

        System.out.println(s);
    }

}
posted @ 2021-09-14 18:09  不是孩子了  阅读(156)  评论(0)    收藏  举报