zoukankan      html  css  js  c++  java
  • springboot应用程序非web方式

    package com.cc8w;
    
    import com.cc8w.service.UserService;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.CommandLineRunner;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.context.ConfigurableApplicationContext;
    
    @SpringBootApplication
    public class SpringbootAppApplication implements CommandLineRunner {
    
    
        @Autowired
        private UserService userService1;
    
    
        /**
         * 第一种非Web方法 :
         * 1.获得context容器
         * 2.在获得标注的bean
         * 3.执行bean方法
         */
        public static void main(String[] args) {
            ConfigurableApplicationContext context =
            SpringApplication.run(SpringbootAppApplication.class, args);
            UserService userService = (UserService) context.getBean("userServiceImpl");
            userService.sayHi();
    
        }
    
    
    
        /**
         * 第二种非Web方法 :
         * 1.启动类集成 CommandLineRunner 接口
         * 2.重写run方法,注解形式@Autowired加入bean
         * 3.重写的run方法可理解为程序入口
         */
    
        @Override
        public void run(String... args) throws Exception {
            userService1.sayHi();
        }
    
    
    }
  • 相关阅读:
    工具包分享-常用工具。by-某某
    渗透常用dos命令,http协议及数据提交方式。 hack 某某
    Hello This Cruel World!
    FFT的一个小技巧
    未完成的模板
    进制转换详细讲解
    CodeForces练习计划
    [SDOI2013]随机数生成器-题解
    动态dp模板
    noip2018游记
  • 原文地址:https://www.cnblogs.com/fps2tao/p/13965014.html
Copyright © 2011-2022 走看看