公司现在配置文件太多了,导致配置文件修改起来还是非常麻烦的。在boss(业务运营支撑系统)中,配置文件是存放在jar包的,通过应用jar包来引用配置文件(区分不同环境)。这种方式虽然能够满足初期需求,但是随着越来越多的项目,配置文件模块也变得臃肿起来。 用了spring-cloud-config虽然还可以,但是没有web界面的方式。这种适合开发人员(特别喜欢这种上传到git的方式来修改配置文件)。但是局限也很明显,只适合这种用spring cloud架构的,对于xml配置的无能为力。
在经过一定的技术调研,还有一个博主网上文章的推荐,发现这个还是比较适合目前公示的需要的。今天折腾了一番,服务终于能够启动起来了。虽然文档还是挺丰富的,但是有一些有一些坑没有标识出来。 对于这么解决这些坑,我将在后续的时间慢慢完善起来。
昨天搭建遇到的问题主要是因为,一个是jvm参数。还有就是yml的配置。这边一些数据库的配置也是用jvm参数的形式来实现的。虽然挺好的,但是不够直观。我把一些配置修改为在yml中实现。 在对应的配置文件中 举一个例子用来借鉴
---
spring:
application:
name: apollo-portal
profiles:
active: development
resources:
cache-period: 3600
logging:
file: /opt/logs/100003173/apollo-portal.log
endpoints:
health:
sensitive: false
management:
security:
enabled: false
health:
status:
order: DOWN, OUT_OF_SERVICE, UNKNOWN, UP
---
server:
port: 18070
spring:
profiles: development
datasource:
url: jdbc:mysql://1.1.1.1:3306/ApolloPortalDB?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&useSSL=false
username: name
password: pwd
driver-class-name: com.mysql.jdbc.Driver
max-active: 50
min-idle: 10
max-idle: 10
initial-size: 15
max-wait: 5
test-on-borrow: true
validation-query: select 1
jpa:
hibernate:
show_sql: true
# ddl-auto: validate
properties:
hibernate:
show_sql: false
format_sql: false
use_sql_comments: false
database: mysql
---
server:
port: 8070
spring:
profiles: production
datasource:
url: jdbc:mysql://2.2.2.2:3306/ApolloPortalDB?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&useSSL=false
username: name
password: pwd
driver-class-name: com.mysql.jdbc.Driver
max-active: 50
min-idle: 10
max-idle: 10
initial-size: 15
max-wait: 5
test-on-borrow: true
validation-query: select 1
jpa:
hibernate:
show_sql: true
# ddl-auto: validate
properties:
hibernate:
show_sql: false
format_sql: false
use_sql_comments: false
database: mysql
同时把application-github.properties 中的配置给注释掉
# DataSource
#spring.datasource.url = ${spring_datasource_url}
#spring.datasource.username = ${spring_datasource_username}
#spring.datasource.password = ${spring_datasource_password}
然后就是配置jvm参数了。
PortalApplication
-Denv=dev -Ddev_meta=http://localhost:8080 -Dfat_meta=http://localhost:8080 -Duat_meta=http://localhost:8080 -Dpro_meta=http://localhost:8080
ConfigServiceApplication
-Denv=dev -Ddev_meta=http://localhost:8080 -Deureka.service.url=http://localhost:8080/eureka/
AdminServiceApplication
-Denv=dev -Ddev_meta=http://localhost:8080 -Deureka.service.url=http://localhost:8080/eureka/
分别启动 ConfigServiceApplication,AdminServiceApplication,PortalApplication 这三个模块,就可以启动了,正常使用了。
访问 http://localhost:8070/ 账号是apollo,密码是admin
mysql的服务降级