spring-cloud / spring-cloud-config

External configuration (server and client) for Spring Cloud
Apache License 2.0
1.95k stars 1.29k forks source link

No active profile set, falling back to default profiles: default #1346

Closed liuyang2010001256 closed 5 years ago

liuyang2010001256 commented 5 years ago

my application run with this error, and when i change config file's name from application-dev.yml to application-ops.yml and change application.yml's active from dev to ops. it run successful,i want to know why? my config:

server.port: 8088
management.port: 9988

spring:
  application:
    name: xxx
  cloud:
    consul:
      enabled: false
      discovery:
        fail-fast: false

management:
  security:
    enabled: false

abc:
  web:
    xxljob:
      enabled: true
      admin:
        addresses: xxx
      executor:
        appname: cmdb
        ip:
        port: 9998
        accessToken: 53aa095311
        logpath: D:\download
        logretentiondays: -1

  data:
      pagehelper:
        helperDialect: mysql
        reasonable: true
        supportMethodsArguments: true
        params: count=countSql
      mybatis:
        typeAliasesPackage: com.xx.devops.xx.business.entity
        mapperLocations:
           classpath: com/xx/devops/xx/fetcher/cmdb/repo/xml/*.xml
      mapper:
        notEmpty: true
      database:
        primary: master
        connection:
          master:
            type: com.zaxxer.hikari.HikariDataSource
            driver-class-name: com.mysql.jdbc.Driver
            url: jdbc:mysql://xx/mysql?useSSL=false&characterEncoding=UTF-8
            username: root
            password: xx
            hikari:
              auto-commit: true
              connection-timeout: 10000
              idle-timeout: 600000
              max-lifetime: 1800000
              minimum-idle: 10
              maximum-pool-size: 10

cmdb.url: xx
cmdb.params: cmdb/params
cmdb.headers: cmdb/headers

(please ignore xx)

spencergibb commented 5 years ago

Please learn how to properly format code and logs.

Can you elaborate what the problem is, what the logs say the error is and how to reproduce it?

liuyang2010001256 commented 5 years ago

my problem is when my application run, it does not find actived config named application-dev.yml, it run with default config named application.yml. and log says No active profile set, falling back to default profiles: default.

my application.yml file

、、、

spring: profiles: active: dev mvc: favicon: enabled: false devtools: restart: enabled: true livereload: enabled: true

logging: level: ROOT: WARN com.longfor: INFO

management: security: enabled: false info: git: enabled: true env: enabled: true endpoints: health: sensitive: false restart: enabled: true shutdown: enabled: true info: enabled: true sensitive: false

、、、

PeichengLiu commented 5 years ago

The log has answered your question. You DIT NOT set any active profile.

You should run your app with specify profile by providing environment variable, e.g.

./mvnw.cmd spring-boot:run -D"spring-boot.run.profiles"=dev
liuyang2010001256 commented 5 years ago

it is idea's problem,tk

stoiandelev commented 1 year ago

Hi, My application properties

spring.profiles.active=@spring.profiles.active@ server.port=8000

My pom.xml file

<?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">

4.0.0
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.1.1</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>Demo_Docker</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Demo_Docker</name>
<description>Demo_Docker</description>
<properties>
    <java.version>17</java.version>
    <spring.profiles.active>development</spring.profiles.active>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <testResources>
        <testResource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
        </testResource>
    </testResources>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>

</build>

My Dockerfile

FROM openjdk:17-jdk-alpine ARG JAR_FILE=out/*.jar COPY ./out/artifacts/Demo_Docker_jar/Demo_Docker.jar app.jar EXPOSE 8000 ENTRYPOINT ["java", "-jar", "/app.jar"]

RestController

@RestController public class hello {

@GetMapping("/")
public String greeting() {
    return "Greeting Sto";
}

INFO FRON INTELLIJ 17:38:36.217 [main] INFO com.example.demo_docker.DemoDockerApplication -- No active profile set, falling back to 1 default profile: "default"

CAN HELP PLS

APP NOT RUNNING ON DOCKER!