springboot项目main函数启动
在controller包下新建appController类
package controller;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
@SpringBootApplication
public class appController extends SpringBootServletInitializer {
public static void main(String[] args){
SpringApplication.run(appController.class,args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(appController.class);
}
}
测试:
新建indexController
新建proController类
启动appController类中的main函数
浏览器输入:localhost:8080/proo
浏览器输入:localhost:8080/index
SpringBoot main方法详解
@SpringBootApplication
public class UdeamApplication {
public static void main(String[] args) {
SpringApplication.run(UdeamApplication.class, args);
}
}
@SpringBootApplication
开启springboot配置注解 ,项目启动入口,用来启动spring容器 , 启动tomcat , 其他包必须与此类在同级目录或者子包下
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。