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();
        }
    
    
    }
  • 相关阅读:
    leetcode第9题判断回文数
    leetcode整数反转第七题
    leetcode刷题两数之和
    找工作之旅
    C#和.Ne学习第五天
    C#和.Ne学习第四天
    C#和.Ne学习第三天
    C#和.Ne学习第二天
    C#和.Ne学习第一天
    从今天开始正事学习C#和.Net了
  • 原文地址:https://www.cnblogs.com/fps2tao/p/13965014.html
Copyright © 2011-2022 走看看