Springboot tasks when starting a project from a database or retrieval system parameters redis

Implement org.springframework.boot.CommandLineRunner interface springboot startup class method

Import org.springframework.boot.CommandLineRunner;
 Import org.springframework.boot.SpringApplication;
 Import org.springframework.boot.autoconfigure.SpringBootApplication;
 Import org.springframework.web.bind.annotation.RequestMapping;
 Import org.springframework.web.bind .annotation.RestController;
 Import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 

@RestController 
@SpringBootApplication // the Spring core of the boot annotation, for opening the automatic configuration 
public  class the StartApplication the implements CommandLineRunner {
 // program may be started directly on this 
    @RequestMapping ( "/")
    String index(){
      return "ok";
    }
  
    public static void main(String[] args) {
        SpringApplication.run(StartApplication.class, args);
    }
    
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //配置静态资源处理
        registry.addResourceHandler("/**")
        .addResourceLocations("classpath:/META-INF/")
        .addResourceLocations("classpath:/hospitalpay");
    }

    @Override
    public void run(String... args) throws Exception {
         // project tasks will start here
         // typically load system for loading parameters 
    } 
}

 

Guess you like

Origin www.cnblogs.com/zyf-yxm/p/11423260.html