org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
使用maven搭建Springboot项目时报如上错误。搜了好多方案,都没有解决错误。
希望下面方案能帮到你。。。
@Controller
public class HelloController {
@RequestMapping("/Hello")
@ResponseBody
public Map<String,Object> showHello(){
Map retMap=new HashMap<String,Object>();
retMap.put("msg", "使用maven构建的SpringBoot项目");
return retMap;
}
}
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(HelloController.class,args);
}
}
原因以及解决方案:App启动类中
SpringApplication.run(HelloController.class,args);
改为
SpringApplication.run(App.class,args);
注意启动类的输入参数。