springboot-java
1. 获取Springboot容器Bean对象调用业务方法
package com.example.springboot; import com.example.springboot.service.StudentService; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ConfigurableApplicationContext; @SpringBootApplication public class Application { public static void main(String[] args) { /** * Springboot项目启动后,返回值是ConfigurableApplicationContext(一个Spring容器) * 它相当于原Spring容器中的启动容器ClasspathXmlApplicationContext */ //获取Springboot容器 ConfigurableApplicationContext applicationContext = SpringApplication.run(Application.class, args); //从Spring容器中获取指定的Bean对象 StudentService studentService = ((StudentService) applicationContext.getBean("studentServiceImpl")); //调用业务方法 String say = studentService.say(); System.out.println(say); } }
2. 实现CommandLineRunner类重写run()方法调用业务方法
package com.example.springboot; import com.example.springboot.service.StudentService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Application implements CommandLineRunner { @Autowired private StudentService studentService; //Springboot启动程序,初始化Spring容器 public static void main(String[] args) { SpringApplication.run(Application.class, args); } //重写CommandLineRunner类的run()方法 @Override public void run(String... args) throws Exception { //调用业务方法 String say = studentService.say("Other Springboot Java !"); System.out.println(say); } }
关闭Springboot启动Logo
//Springboot启动程序,初始化Spring容器 public static void main(String[] args) { //获取入口Springboot类 SpringApplication springApplication = new SpringApplication(Application.class); //设置参数 springApplication.setBannerMode(Banner.Mode.OFF); springApplication.run(args); // SpringApplication.run(Application.class, args); }
修改baidu
相关推荐
与卿画眉共浮生 2020-11-13
CaesarHome 2020-11-09
瑞风轻拂 2020-11-02
hellowordmonkey 2020-11-02
丽丽 2020-10-30
流年浅滩 2020-10-23
feinifi 2020-10-14
yangjinpingc 2020-10-09
RickyIT 2020-09-27
lisongchuang 2020-09-27
permanent00 2020-09-15
李玉志 2020-08-19
spring 2020-08-18
meleto 2020-08-17
幸运小侯子 2020-08-14
85407718 2020-08-09
csuzxm000 2020-08-02
咻pur慢 2020-08-02
libowenhit 2020-07-29