zoukankan      html  css  js  c++  java
  • SpringBoot非web方式启动

    pom.xml

    <parent>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-starter-parent</artifactId>
    		<version>1.5.10.RELEASE</version>
    	</parent>
    	<dependencies>
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter</artifactId>
    		</dependency>
    	</dependencies>
    	<build>
    		<finalName>${project.artifactId}</finalName>
    		<plugins>
    			<!-- java编译插件 -->
    			<plugin>
    				<groupId>org.apache.maven.plugins</groupId>
    				<artifactId>maven-compiler-plugin</artifactId>
    				<configuration>
    					<source>1.8</source>
    					<target>1.8</target>
    					<encoding>UTF-8</encoding>
    				</configuration>
    			</plugin>
    			<plugin>
    				<groupId>org.springframework.boot</groupId>
    				<artifactId>spring-boot-maven-plugin</artifactId>
    			</plugin>
    		</plugins>
    	</build>
    

    启动类

    第一种方式
    @SpringBootApplication
    public class App {
    
    	public static void main(String[] args) {
    		ConfigurableApplicationContext context = SpringApplication.run(App.class, args);
    		HelloService helloService = context.getBean(HelloService.class);
    		helloService.say();
    	}
    }
    第二种方式
    @SpringBootApplication
    public class App implements ApplicationRunner {
    
    	public static void main(String[] args) {
    		new SpringApplicationBuilder().sources(App.class).web(false).run(args);
    	}
    	@Autowired
    	private HelloService helloService
    	@Override
    	public void run(ApplicationArguments args) throws Exception {
    	    helloService.say();
    	}
    }
    
    
  • 相关阅读:
    Html 回顾
    Parallel 并行编程
    Task---常用的多线程(基于多线程线程)
    Threadpool 可以对线程加以管理的封装
    AsyncThreads---异步多线程
    Abstract 封装,继承,多态
    IO&&Serize 利用线程Thread.Sleep实现"自动输出"
    Ling && Lambda
    Delegate&&Event
    Delegate &&Lambda
  • 原文地址:https://www.cnblogs.com/yinchh/p/12391311.html
Copyright © 2011-2022 走看看