何か変わったことが起こりました。私はファイル名が 'application.yml/application.properties'でない限り、Springクラウドの設定でネイティブファイルやクラウド設定ファイルを読み込めないという問題を解決する方法は知らない。ファイル名がアプリケーションでない限り、Springクラウド設定はネイティブ設定ファイルをロードできません
以下のコードは、私の設定です:
のpom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<relativePath/>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>micro-certification-config-center</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
CONFIGSERVER:
@SpringBootApplication
@EnableConfigServer
public class ConfigServer {
public static void main(String[] args) {
SpringApplication.run(ConfigServer.class, args);
}
}
application.yml:
server:
port: 8000
spring:
cloud:
config:
server:
native:
search-locations: classpath:/shared
profiles:
active: native
共有フォルダstructor :
の リソース
は - - アプリケーション - dev.yml
- - - SMS-dev.yml
それはよさそうだし、エラーなしでうまく実行されますが、私はhttp://127.0.0.1:8000/configCenter/dev/masterを訪問したときに、
共有しましたアプリケーションプロパティのソースのみが表示されます。
応答:
{
"name": "configCenter",
"profiles": [
"dev"
],
"label": "master",
"version": null,
"state": null,
"propertySources": [
{
"name": "classpath:/shared/application-dev.yml",
"source": {
"logging.level.org.springframework.security": "INFO",
"eureka.instance.prefer-ip-address": true,
"eureka.client.serviceUrl.defaultZone": "http://registry:8761/eureka/",
"security.oauth2.resource.user-info-uri": "http://auth-service:5000/uaa/users/current",
"spring.rabbitmq.host": "rabbitmq"
}
}
]
}
サーバーコンソール:
2017-08-24 22:34:08.055 INFO 30010 --- [nio-8000-exec-4] s.c.a.AnnotationConfigApplicationContext : Refreshing org.spring[email protected]4a931797: startup date [Thu Aug 24 22:34:08 CST 2017]; root of context hierarchy
2017-08-24 22:34:08.062 INFO 30010 --- [nio-8000-exec-4] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2017-08-24 22:34:08.075 INFO 30010 --- [nio-8000-exec-4] o.s.c.c.s.e.NativeEnvironmentRepository : Adding property source: classpath:/shared/application-dev.yml
2017-08-24 22:34:08.075 INFO 30010 --- [nio-8000-exec-4] s.c.a.AnnotationConfigApplicationContext : Closing org.spring[email protected]4a931797: startup date [Thu Aug 24 22:34:08 CST 2017]; root of context hierarchy
上記のすべてが唯一働い 'application.yml' ファイルを示しています。
誰かが私を助けることができますか?どうもありがとう!
'sms-dev.yml'を読み込むと思ったら、spring.application.nameはsmsである必要があります。 – spencergibb
ああ、ありがとう!@spencergibb – WhiteWater