spring boot 报错 Unable to start embedded container;

想做个rest风格的控制器,简单例子:

 

[html]  view plain  copy
  1. @RestController  
  2. @RequestMapping("/user")  
  3. public class UserController {  
  4.   
  5.     @RequestMapping("/{id}")    
  6.     public User view(@PathVariable("id") Long id){  
  7.         User user = new User();  
  8.         user.setId(id);  
  9.         user.setName("linli");  
  10.           
  11.         return user;  
  12.     }  
  13.   
  14.       
  15.     public static void main(String[] args) {  
  16.         // TODO Auto-generated method stub  
  17.       SpringApplication.run(UserController.class,args);  
  18.         //System.out.println("sss");  
  19.     }  
  20.       
  21. }  


启动的时候报错:

[html]  view plain  copy
  1.   .   ____          _            __ _ _  
  2.  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \  
  3. ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \  
  4.  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )  
  5.   '  |____| .__|_| |_|_| |_\__, | / / / /  
  6.  =========|_|==============|___/=/_/_/_/  
  7.  :: Spring Boot ::        (v1.3.1.RELEASE)  
  8.   
  9. 2015-12-22 09:30:23.579  INFO 3208 --- [           main] controller.UserController                : Starting UserController on IQSZ-D2678 with PID 3208   
[html]  view plain  copy
  1. 2015-12-22 09:30:23.582  INFO 3208 --- [           main] controller.UserController                : No active profile set, falling back to default profiles: default  
  2. 2015-12-22 09:30:23.879  INFO 3208 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@12ceb70: startup date [Tue Dec 22 09:30:23 CST 2015]; root of context hierarchy  
  3. 2015-12-22 09:30:24.391  WARN 3208 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.  
  4. 2015-12-22 09:30:25.211 ERROR 3208 --- [           main] o.s.boot.SpringApplication               : Application startup failed  
  5.   
  6. org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.  
  7.     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]  
  8.     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]  
  9.     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]  
  10.     at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:764) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]  
  11.     at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:357) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]  
  12.     at org.springframework.boot.SpringApplication.run(SpringApplication.java:305) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]  
  13.     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1124) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]  
  14.     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1113) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]  
  15.     at controller.UserController.main(UserController.java:28) [classes/:na]  
  16. Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.  
  17.     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:185) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]  
  18.     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:158) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]  
  19.     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]  
  20.     ... 8 common frames omitted  

 

报的是  无法启动嵌入容器,工厂类不存在。

在类头加上  @EnableAutoConfiguration。就OK了。这个接口看名字是允许自动配置。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值