求助大目老师和各位同学 集成gateway oracle6 后报错

来源:10-3 编写Spring Cloud Gateway

风行一里

2020-11-08

大目老师您好
我springboot版本 2.1.8
spring-alibaba 版本2.1.2.RELEASE
spring-cloud版本 Greenwich.SR3

集成了mybatis 和 本机maven导入的oracle6的oracle

    <mybatis.plus.version>3.2.0</mybatis.plus.version>
    <druid.version>1.1.10</druid.version>
    <mysql.version>8.0.13</mysql.version>
    <beetl.version>2.9.10</beetl.version>
    <log4j.version>1.2.17</log4j.version>

配置

server:
port: 8000
spring:
application:
name: gjj-gateway
datasource:
url: jdbc:oracle:thin:@39.98.162.182:1521:orcl
driver-class-name: oracle.jdbc.driver.OracleDriver
username: ZHFWPTDEV
password: 123456
cloud:
nacos:
server-addr: localhost:8848
gateway:
discovery:
locator:
enabled: true
logging:
config: classpath:logback.xml
mybatis-plus:
mapper-locations: classpath*:com/ileadtech/slytgjj/**/dao/mapper/xml/*Mapper.xml
global-config:
id-type: 1 #0:数据库ID自增 1:用户输入id 2:全局唯一id(IdWorker) 3:全局唯一ID(uuid)
db-column-underline: false
refresh-mapper: true

错误提示为
Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
ERROR (SpringApplication.java:823)- Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘statViewServletRegistrationBean’ defined in class path resource [com/alibaba/druid/spring/boot/autoconfigure/stat/DruidStatViewServletConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.ServletRegistrationBean]: Factory method ‘statViewServletRegistrationBean’ threw exception; nested exception is java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:607)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204)
at com.ileadtech.slytgjj.gateway.GatewayApplication.main(GatewayApplication.java:10)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.ServletRegistrationBean]: Factory method ‘statViewServletRegistrationBean’ threw exception; nested exception is java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622)
… 19 common frames omitted
Caused by: java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader1.run(URLClassLoader.java:362)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.net.URLClassLoader.findClass(URLClassLoader.java:361)atjava.lang.ClassLoader.loadClass(ClassLoader.java:424)atsun.misc.Launcher1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher1.run(URLClassLoader.java:362)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.net.URLClassLoader.findClass(URLClassLoader.java:361)atjava.lang.ClassLoader.loadClass(ClassLoader.java:424)atsun.misc.LauncherAppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader1.run(URLClassLoader.java:362)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.net.URLClassLoader.findClass(URLClassLoader.java:361)atjava.lang.ClassLoader.loadClass(ClassLoader.java:424)atsun.misc.Launcher1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher1.run(URLClassLoader.java:362)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.net.URLClassLoader.findClass(URLClassLoader.java:361)atjava.lang.ClassLoader.loadClass(ClassLoader.java:424)atsun.misc.LauncherAppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.alibaba.druid.spring.boot.autoconfigure.stat.DruidStatViewServletConfiguration.statViewServletRegistrationBean(DruidStatViewServletConfiguration.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
… 20 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServlet
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
… 50 common frames omitted

麻烦老师给指点一下 谢谢

写回答

2回答

大目

2020-11-08

在Gateway开始我有讲过,Gateway不是基于Servlet的,是基于Webflux、Reactor、Netty的;

而Druid的监控是基于Servlet的,Druid引入后,它尝试找Servlet容器,但是没有找到。

所以报了这玩意:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘statViewServletRegistrationBean’ defined in class path resource [com/alibaba/druid/spring/boot/autoconfigure/stat/DruidStatViewServletConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.ServletRegistrationBean]: Factory method ‘statViewServletRegistrationBean’ threw exception; nested exception is java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet

而Gateway又不支持跑在Servlet容器中,所以两者想共存基本是没辙了。

解决方案:把Druid去掉,换用其他不需要Servlet的数据库连接池,比如Hikari。


此外,为什么要在Gateway上引入数据库?网关一般应该是比较轻量的,你打算把什么操作数据库的业务写到网关去?


0
2
大目
回复
风行一里
自己写个过滤器工厂即可。
2020-11-09
共2条回复

风行一里

提问者

2020-11-08

https://blog.csdn.net/mameng1988/article/details/109296287

0
0

Spring Cloud Alibaba微服务从入门到进阶

面向未来微服务:熟练掌握Spring Cloud Alibaba

3054 学习 · 1322 问题

查看课程