Springboot项目启动后访问不到Controller

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);
     }
 
 }
posted @ 2019-06-18 16:04  xiaoshen666  阅读(1789)  评论(0编辑  收藏  举报