apolloconfig / apollo

Apollo is a reliable configuration management system suitable for microservice configuration management scenarios.
https://www.apolloconfig.com
Apache License 2.0
29.17k stars 10.21k forks source link

configservice 本地编译后,部署启动报告“Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.” #2142

Closed ardenxu closed 5 years ago

ardenxu commented 5 years ago
  1. 用官方的包部署配置中心没有任何问题,client/configservice/adminservice/portal均能正常工作。
  2. 因想学习下server端 configservice/adminservice 及客户端交互,将/src/main/resource/logback 日志级别 升级为debug。
  3. 本地编译/打包无问题。
  4. 部署到服务器, 配置application-github.properties后,启动configservice 报告如下错误:

    APPLICATION FAILED TO START


Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

Action: Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

在mvn 编译打包过程中,如何告知应用应该读取 config/application-github.properties 下配置。

多谢!!!

ardenxu commented 5 years ago

更新 startup.sh 指定 application-github.properties具体路径,configservice 启动时又报告如下错误: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1277) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1265) at com.ctrip.framework.apollo.configservice.ConfigServiceApplication.main(ConfigServiceApplication.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.boot.loader.MainMethodRunner.run(MainMethodRunner.java:54) at java.lang.Thread.run(Thread.java:748) Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:126) at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.(TomcatWebServer.java:86) at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:413) at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:174) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:179) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152) ... 14 common frames omitted Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration': Unsatisfied dependency expressed through field 'eurekaServerConfig'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'eurekaServerConfig' defined in class path resource [org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration$EurekaServerConfigBeanConfiguration.class]: Unsatisfied dependency expressed through method 'eurekaServerConfig' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'apolloEurekaClientConfig' defined in URL [jar:file:/home/apollo/configservice-1.3.0/apollo-configservice.jar!/lib/apollo-biz-1.3.0-SNAPSHOT.jar!/com/ctrip/framework/apollo/biz/eureka/ApolloEurekaClientConfig.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bizConfig': Invocation of init method failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet

对springboot框架不熟悉,那位专家能给指点下?

nobodyiam commented 5 years ago

如果是学习的话,建议通过IDE方式启动,参考Apollo开发指南

如果只是要修改日志级别,那么在startup.sh中的JAVA_OPTS中加入logging.level配置即可

如果实在要自己打包,那么可以参考通过源码构建

ardenxu commented 5 years ago

多谢宋工。 就是参照“通过源码构建”说明本地下载1.3源码使用eclipse 构建的。

  1. 本地编译没有问题,.部署之后,初始化阶段 数据库连接问题已修复。 2 启动阶段仍报告如下“UnsatisfiedDependencyException” , 能否帮忙指点类似问题如何解决? 官方提供1.3的部署包,是在linux下用build.sh 构建的,还是利用windows IDE构建的? 都是使用官方pom 构建的话, 本地构建不清楚为何有类似问题。因后续需要在apollo基础上增加内部适配功能,所以需要能本地编译后部署,还请指点下。 谢谢!!

“Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration': Unsatisfied dependency expressed through field 'eurekaServerConfig';”

nobodyiam commented 5 years ago

看caused by部分的日志信息,估计是你本地maven仓库有问题

ardenxu commented 5 years ago

该问题已确认是startup.sh 启动时的配置问题,针对自己IDE编译的jar包,启动时增加-Dapollo_profile=github 的选项就OK。

export JAVA_OPTS="$JAVA_OPTS -Dapollo_profile=github -Dserver.port=$SERVER_PORT -Dlogging.file=$LOG_DIR/$SERVICE_NAME.log -Xloggc:$LOG_DIR/gc.log -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=5M -XX:HeapDumpPath=$LOG_DIR/HeapDumpOnOutOfMemoryError/"

否则会报告如下错误:


APPLICATION FAILED TO START


Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

Action:

Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

master336 commented 4 years ago

根据异常可以看出,应用并未读取到有效的数据库配置,应用默认的配置为application-github.properties,所以在启动的时候增加VM启动参数 -Dapollo_profile=github 激活对应的配置即可