Giter VIP home page Giter VIP logo

Comments (11)

nobodyiam avatar nobodyiam commented on May 15, 2024

可以的,apollo注入配置的原理和spring cloud config一样的。参考Java客户端使用指南即可。

补充一点,目前注入的配置需要时properties格式,yml格式还不支持。

from apollo.

blue-ali avatar blue-ali commented on May 15, 2024

谢谢,在使用过程中还碰到一些问题想问
我自己写了一个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.

nobodyiam avatar nobodyiam commented on May 15, 2024

看上去是脚本有点问题。。你如果打开apollo-core.jar里面的apollo-env.properties就知道了。

建议还是装一个Git Bash,然后跑build.sh吧。

from apollo.

blue-ali avatar blue-ali commented on May 15, 2024

谢谢回答,我用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.

nobodyiam avatar nobodyiam commented on May 15, 2024

build.sh里面有数据库配置的,你照着做就没问题啊。这部分配置实际上是会替换apollo-common下的application-dev.properties,你打完包看一下就明白了。

vm参数没有加载到的问题,这个可以在启动过程中看一下进程参数,如Linux下是ps aux | grep java,Windows不太了解。。。

from apollo.

blue-ali avatar blue-ali commented on May 15, 2024

谢谢,已经解决了,我build.sh里配置的问题。
我还有点疑问,为什么数据库这些配置不放在application.yml里,而是在build的时候用参数打到包里?感觉参数配置这有点乱,像eureka的地址配置是在数据库里的,而configservice工程里的bootstrap里也配了,但是好像没起作用,最后读取的还是数据库里的地址。

from apollo.

nobodyiam avatar nobodyiam commented on May 15, 2024

数据库配置是放在application-dev.properties,和application.yml是一个道理。build的时候传入参数最终就是写入了application-dev.properties。至于为啥不直接写在文件中很好理解吧,一个是因为每个环境不一样,一个是开源代码不能写啊。

eureka的配置因为会动态调整的,所以文件只能是一个fallback,最终还是要以数据库为准的。

from apollo.

blue-ali avatar blue-ali commented on May 15, 2024

十分感谢~

from apollo.

wzxit avatar wzxit commented on May 15, 2024

application.properties中使用,如:spring.datasource.url: ${someKeyFromApollo:someDefaultValue}
缺点是这类注入的值在变化后不会重新注入,需要重启才会更新。

这是要重新启动实例才能加载吗?

from apollo.

wzxit avatar wzxit commented on May 15, 2024

还有,有没有spring boot 使用apollo的详细点的例子呢?

from apollo.

nobodyiam avatar nobodyiam commented on May 15, 2024

spring placeholder在运行时重新注入有几种方式

  1. 重启
  2. 监听config change listener手动重新注入
  3. 使用RefreshScope

from apollo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.