Comments (11)
可以的,apollo注入配置的原理和spring cloud config一样的。参考Java客户端使用指南即可。
补充一点,目前注入的配置需要时properties格式,yml格式还不支持。
from apollo.
谢谢,在使用过程中还碰到一些问题想问
我自己写了一个demo,加载不到配置,在启动的时候会有WARN
2017-03-30 10:30:28.156 WARN 305728 --- [ main] c.c.f.a.i.AbstractConfigRepository : Sync config failed, will retry. Repository class com.ctrip.framework.apollo.internals.RemoteConfigRepository, reason: Get config services failed from http://localhost:8080 -Dfat_meta=http://localhost:8080 -Duat_meta=http://localhost:8080 -Dpro_meta=http://localhost:8080/services/config?appId=ApolloTest&ip=192.168.11.10 [Cause: Could not complete get operation [Cause: For input string: "8080 -Dfat_meta=http:" [Cause: For input string: "8080 -Dfat_meta=http:"]]]
我想可能是不是我build的时候出的问题,因为在win环境开发,我把build.sh改成了build.bat,内容如下
`:: apollo config db info
set apollo_config_db_url=jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8
set apollo_config_db_username=root
set apollo_config_db_password=000000
:: apollo portal db info
set apollo_portal_db_url=jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8
set apollo_portal_db_username=root
set apollo_portal_db_password=000000
:: meta server url
set dev_meta=http://localhost:8080
set fat_meta=http://localhost:8080
set uat_meta=http://localhost:8080
set pro_meta=http://localhost:8080
set META_SERVERS_OPTS="-Ddev_meta=%dev_meta% -Dfat_meta=%fat_meta% -Duat_meta=%uat_meta% -Dpro_meta=%pro_meta%"
:: # =============== Please do not modify the following content =============== #
echo %META_SERVERS_OPTS%
pause
cd ..
rem package config-service and admin-service
echo "==== starting to build config-service and admin-service ===="
call mvn clean package -DskipTests -pl apollo-configservice,apollo-adminservice -am -Dapollo_profile=dev -Dspring_datasource_url=%apollo_config_db_url% -Dspring_datasource_username=%apollo_config_db_username% -Dspring_datasource_password=%apollo_config_db_password%
echo "==== building config-service and admin-service finished ===="
pause
echo "==== starting to build portal ===="
call mvn clean package -DskipTests -pl apollo-portal -am -Dapollo_profile=dev -Dspring_datasource_url=%apollo_portal_db_url% -Dspring_datasource_username=%apollo_portal_db_username% -Dspring_datasource_password=%apollo_portal_db_password% %META_SERVERS_OPTS%
echo "==== building portal finished ===="
pause
echo "==== starting to build client ===="
call mvn clean install -DskipTests -pl apollo-client -am %META_SERVERS_OPTS%
echo "==== building client finished ===="
pause`
看起来问题似乎出在set META_SERVERS_OPTS上?这里应该怎么改?
这个meta地址指的就是configservice的地址还是configservice里eureka的地址?如果我想把服务注册到自己的eureka上可以么?
还有打包只能通过这种脚本的方式打包么?
from apollo.
看上去是脚本有点问题。。你如果打开apollo-core.jar里面的apollo-env.properties就知道了。
建议还是装一个Git Bash,然后跑build.sh吧。
from apollo.
谢谢回答,我用git bash build后,在eclipse里通过vm参数
-Dapollo_profile=dev -Dspring.datasource.url=jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8 -Dspring.datasource.username=root -Dspring.datasource.password=000000 -Dlogging.file=d:/logs/apollo-assembly.log
这样启动没有问题,但是用java -jar 加上vm参数的方式启动会报错
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO)
似乎是vm参数没有加载到?改用target的zip包里的startup.sh启动还是一样的问题,我又修改了工程里的application.yml加上了datasource的配置但是还是不管用,这个数据库的配置应该放在哪里加载?感觉自己已经完全懵逼了。。
from apollo.
build.sh里面有数据库配置的,你照着做就没问题啊。这部分配置实际上是会替换apollo-common下的application-dev.properties,你打完包看一下就明白了。
vm参数没有加载到的问题,这个可以在启动过程中看一下进程参数,如Linux下是ps aux | grep java
,Windows不太了解。。。
from apollo.
谢谢,已经解决了,我build.sh里配置的问题。
我还有点疑问,为什么数据库这些配置不放在application.yml里,而是在build的时候用参数打到包里?感觉参数配置这有点乱,像eureka的地址配置是在数据库里的,而configservice工程里的bootstrap里也配了,但是好像没起作用,最后读取的还是数据库里的地址。
from apollo.
数据库配置是放在application-dev.properties,和application.yml是一个道理。build的时候传入参数最终就是写入了application-dev.properties。至于为啥不直接写在文件中很好理解吧,一个是因为每个环境不一样,一个是开源代码不能写啊。
eureka的配置因为会动态调整的,所以文件只能是一个fallback,最终还是要以数据库为准的。
from apollo.
十分感谢~
from apollo.
application.properties中使用,如:spring.datasource.url: ${someKeyFromApollo:someDefaultValue}
缺点是这类注入的值在变化后不会重新注入,需要重启才会更新。
这是要重新启动实例才能加载吗?
from apollo.
还有,有没有spring boot 使用apollo的详细点的例子呢?
from apollo.
spring placeholder在运行时重新注入有几种方式
- 重启
- 监听config change listener手动重新注入
- 使用RefreshScope
from apollo.
Related Issues (20)
- 关于使用yaml配置的问题 HOT 2
- 缺乏用户管理相关的开放 API HOT 5
- 删除项目后异常 HOT 5
- 怎么没有mapper.xml文件 HOT 3
- 使用 H2 内存数据库,自动初始化快速启动失败,日志并没有错误日志,请问这是什么原因? HOT 8
- The management platform has added a new global configuration search feature HOT 3
- Spring 中 ConfigurationProperties 配置热更新问题 HOT 5
- 2.1.0版本,非 properties 格式的公共配置文件如yml的继承是否依然是在整个文件内容粒度进行,如果是请明确告知用户 HOT 5
- 增加不同环境下所有namespace的一键同步 HOT 3
- Add more observability in apollo config client HOT 2
- 请教 Bash 脚本如何请求开启了访问密钥的配置项 HOT 6
- apollo.meta; nested exception is java.net.UnknownHostException: apollo.meta HOT 5
- When is the 2.3.0 release scheduled? HOT 2
- Portal 模块 RestTemplate 支持配置 ConnectionTimeToLive
- apollo2.1.0集成pgsql,求给一份pgsql的sql文件。mysql的不可以用 HOT 3
- 无法删除旧的配置 HOT 5
- 在项目namespace数量比较多的情况下(大约1000个),打开页面加载速度很慢,比较影响用户体验,这个是否有什么优化改进方案? HOT 7
- Apollo是否可以支持按照key维度来发布? HOT 2
- 1.8.0,接入一个app.id 使用多个namespace的时候,多个namesapce均开启了accesskey.sercet,这时候接入的配置代码要怎么写呢 HOT 3
- OidcLocalUserService throw an Exception when executing createLocalUser in OIDC profile HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apollo.