1、问题描述
搭建一个简单的Springboot项目,最开始将启动类main函数与controller放到一个类里,可以正常启动和访问,但是将两个分开再启动时访问就会报错:This application has no explicit mapping for /error, so you are seeing this as a fallback.
2、解决方案
在main函数启动类上加注解:@SpringBootApplication(scanBasePackages = “com”) 问题即可解决。
package com.mao2080; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication(scanBasePackages = "com") @EnableAutoConfiguration public class Application { public static void main(String[] args) throws Exception { SpringApplication.run(Application.class, args); } }
版权声明:本文为Anfen0原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。