当前位置: 首页 > 知识库问答 >
问题:

Spring云配置搜索路径vs回购目录结构

顾亦
2023-03-14

我正在尝试使用Git(Bitbucket)上的远程存储库运行SpringCloudConfigServer(集中式配置服务)。但不管我在应用程序中设置了什么搜索路径。属性,它总是返回空数组,而不是存储库中的值。

所以,我的存储库看起来像这样(在master分支上):

app1/ (dir)
  app1.yml
  app1-test.yml
  app1-uat.yml
  ...
app2/ (dir)
  app2.yml
  app2-test.yml
  app2-uat.yml
  ...

我的src/main/resources/application。特性:

server.port=8888
spring.cloud.config.server.git.uri=https://bitbucket.repo.url/repo.git
spring.cloud.config.server.git.cloneOnStart=true
spring.cloud.config.server.git.force-pull=true
spring.cloud.config.server.git.skipSslValidation=true
spring.cloud.config.server.git.username=repo_login
spring.cloud.config.server.git.password=repo_pass
spring.cloud.config.server.git.searchPaths='{application]' # Tried also '{application}/{application}-{profile}' and '{application}/{application}-{profile}.yml'
spring.security.user.name=config_user
spring.security.user.password=config_pass

src\main\java\example\centralizedconfigurationservice\ConfigServer。爪哇:

package example.centralizedconfigurationservice;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;

@SpringBootApplication
@EnableConfigServer
public class ConfigServer {
    
    public static void main(String[] arguments) {
        SpringApplication.run(ConfigServer.class, arguments);
    }
}

波姆。xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>example</groupId>
    <artifactId>centralized-configuration-service</artifactId>
    <version>1.0.0</version>
    <name>centralized-configuration-service</name>
    <description>Desc...</description>
    <properties>
        <java.version>11</java.version>
        <spring-cloud.version>2020.0.3</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    
   <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-test</artifactId>
     <version>2.1.7.RELEASE</version>
   </dependency>
 </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.1.0</version>
            </plugin>  
        </plugins>
    </build>
</project>

我正在用mvnw

./mvnw spring-boot:run

来自启动服务器的日志:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.5.2)

2021-07-20 13:51:32.444  INFO 35 --- [           main] p.c.p.n.c.ConfigServer                   : Starting ConfigServer using Java 11.0.1 on 67421f38de7b with PID 35 (/app/target/classes started by root in /app)
2021-07-20 13:51:32.449  INFO 35 --- [           main] p.c.p.n.c.ConfigServer                   : No active profile set, falling back to default profiles: default
2021-07-20 13:51:33.311  INFO 35 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=3aa36d2a-4db1-39bb-8278-6d749acb1c11
2021-07-20 13:51:33.582  INFO 35 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8888 (http)
2021-07-20 13:51:33.594  INFO 35 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-07-20 13:51:33.594  INFO 35 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.48]
2021-07-20 13:51:33.693  INFO 35 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-07-20 13:51:33.693  INFO 35 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1151 ms
2021-07-20 13:51:34.124  INFO 35 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Will secure any request with [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@228bda54, org.springframework.security.web.context.SecurityContextPersistenceFilter@5de5e95, org.springframework.security.web.header.HeaderWriterFilter@314b9e4b, org.springframework.security.web.csrf.CsrfFilter@40d23c82, org.springframework.security.web.authentication.logout.LogoutFilter@34c70b5e, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@42383cb0, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter@4f2d995e, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter@75b6dd5b, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@d2e6b0b, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@303c55fa, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@7c2924d7, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@b3e86d5, org.springframework.security.web.session.SessionManagementFilter@51dae791, org.springframework.security.web.access.ExceptionTranslationFilter@949c598, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@7316523a]
2021-07-20 13:51:35.979  INFO 35 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8888 (http) with context path ''
2021-07-20 13:51:36.000  INFO 35 --- [           main] p.c.p.n.c.ConfigServer                   : Started ConfigServer in 4.043 seconds (JVM running for 4.525)

当我尝试获得'http://localhost:8888/app1/test'im(登录后):

{"name":"app1","profiles":["test"],"label":null,"version":"f4e9867b34eacdc03bbd5478c12cf64fbadcb867","state":null,"propertySources":[]}

有人知道我应该设置什么搜索路径来让它工作吗?

共有1个答案

阴鸿才
2023-03-14

通过从应用程序切换,我可以使用它。应用程序的属性。yml和设置:

spring:
  cloud:
    config:
      server:
        git:
          uri: ...
          searchPaths:
            - '*/**'
 类似资料:
  • 我有一个工作的Spring cloud配置服务器,它从git存储库中提供配置。所有配置都存储在存储库中的根目录下。它们被命名为< code>{name}-{profile}。yml。 我已将目录结构更改为 当我< code > curl http://configserver:8888/appname/my profile 配置服务器时,我得到一个json响应,但是propertySources为

  • 在SublimeText 2中,我可以执行以下操作:<code>cmd t</code> 然后键入文件名或文件夹名,显示的结果是与我正在搜索的术语匹配的文件,以及位于我正在搜索的术语的子文件夹中的文件,例如,如果我的目录结构如下所示: 我可以做命令 和类型和唯一的两个选项,将显示将是和文件,我可以键向下导航或键入添加更多的搜索词和唯一的选项将是 如何在RubyMine中获得相同的功能

  • 我需要为微服务列表创建一个专用配置服务器。下面是应用程序的片段。配置服务器的yml: 我在访问这些微服务配置时遇到了问题。 文档 http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_spring_cloud_config_server 提到可以在 searchPaths 变量中使用通配符 {application

  • 我想通过将参数作为路径变量传递来自定义我的spring-data-rest搜索方法路径,如下所示 搜索资源列出了以下链接 如何使用路径参数公开搜索url?

  • 我从Gradle得到以下错误 这是我的建筑Gradle 调试运行表明它试图用Ivy而不是Maven解决依赖关系?

  • 回到Jooq2.5,看起来可以通过FactoryOperations类设置PostgreSQL搜索路径,但Jooq3.5中没有该类。显然,FactoryOperations分为DSL和DSLContext,但我似乎找不到use(Schema)方法的结尾。如何在较新版本的jOOQ中设置PostgreSQL搜索路径?