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 , 其他包必须与此类在同级目录或者子包下
以上就是如何在springboot项目中启动main函数的详细内容,更多请关注Work网其它相关文章!