首页 / SERVLET / bug 记录 Unable to start ServletWebServerApplicationContext due to multiple ServletWebServerFactory beans
bug 记录 Unable to start ServletWebServerApplicationContext due to multiple ServletWebServerFactory beans
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了bug 记录 Unable to start ServletWebServerApplicationContext due to multiple ServletWebServerFactory beans,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2747字,纯文字阅读大概需要4分钟。
内容图文
![bug 记录 Unable to start ServletWebServerApplicationContext due to multiple ServletWebServerFactory beans](/upload/InfoBanner/zyjiaocheng/1310/f38f2feedcb1495bb7f3cedab6aab0a0.jpg)
错误描述:大致意思就是有多个ServletWebServerFactory spring不知道启动那个
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext
due to multiple ServletWebServerFactory beans : tomcatServletWebServerFactory,webServerFactory at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
起因:
最近公司要做小程序,由于微信要求接口必须是https的,然后就开始springboot整合https,整合https具体细节就不说了。
便于用户体验,让用户可以http也可以正常访问https。配置如下:
@Bean public Connector connector(){ Connector connector=new Connector("org.apache.coyote.http11.Http11NioProtocol"); connector.setScheme("http"); connector.setPort(80); connector.setSecure(false); connector.setRedirectPort(serverPortHttps); return connector; } @Bean public TomcatServletWebServerFactory tomcatServletWebServerFactory(Connector connector){ TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() { @Override protected void postProcessContext(Context context) { SecurityConstraint securityConstraint = new SecurityConstraint(); securityConstraint.setUserConstraint("CONFIDENTIAL"); SecurityCollection collection = new SecurityCollection(); collection.addPattern("/*"); securityConstraint.addCollection(collection); context.addConstraint(securityConstraint); } }; tomcat.addAdditionalTomcatConnectors(connector); return tomcat; }
好了启动。。。。。噩梦开始报错 ····????
代码写的名名白白就只有一个 TomcatServletWebServerFactory 怎么会有多个。。。。
好吧!还是先去网上查一下。。。
找了半天基本都是这样的错误
Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
人家都是缺少。。。我这。。。
上述错误基本都是缺少web包
网上没找到怎么办呢?
去看看源码吧。
进去看看
报错的地方是找到了
开调试确实是有两个servlet, 为啥会有两个呢。
让后我把 TomcatServletWebServerFactory bean 注释掉,结果就可以正常启动。
咦好奇怪。
然后我就去看我的配置。
天~~·我发现了什么。。。
我啥时候配置的。。。终于找到了问题的原因,之前配置个TomcatServletWebServerFactory 忘记了,所以启动会有两个servlet。
自己给自己挖坑~~~
原文:https://www.cnblogs.com/chancy/p/12830093.html
内容总结
以上是互联网集市为您收集整理的bug 记录 Unable to start ServletWebServerApplicationContext due to multiple ServletWebServerFactory beans全部内容,希望文章能够帮你解决bug 记录 Unable to start ServletWebServerApplicationContext due to multiple ServletWebServerFactory beans所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。