programing

스프링 부팅이 application.properties 파일을 인식하지 않습니다.

lastmemo 2023. 3. 17. 19:34
반응형

스프링 부팅이 application.properties 파일을 인식하지 않습니다.

Spring Boot을 사용하여 DynamoDb 클라이언트를 설정하려고 하는데 엔드포인트와 설정 정보를 resources/application.properties 파일에 저장했습니다.단, Spring Boot에서는 이러한 속성이 인식되지 않는 것 같습니다.같은 파일에 저장되어 있는 "server.default" 키를 선택하기 때문에 파일 자체를 확실하게 인식합니다.

다음은 application.properties 파일과 속성을 로드하려는 클래스입니다(DynamoDBClientMapper).

amazon.dynamodb.endpoint=http://localhost:8000/
amazon.dynamodb.region=us-west-1
amazon.aws.accesskey=key
amazon.aws.secretkey=key2

server.port=8080

프로젝트 구조는 다음과 같습니다.

다음은 속성을 로드하려는 관련 클래스입니다.새로운 속성 파일과 함께 @PropertySource 주석을 사용하려고 했습니다.AutoConfiguration. 단, 둘 다 속성 파일을 등록하지 않습니다.

@PropertySource("database.properties")
public class DynamoClientMapper {

    @Value("${amazon.dynamodb.endpoint}")
    private String amazonDynamoDBEndpoint;

    @Value("${amazon.aws.accesskey}")
    private String amazonAWSAccessKey;

    @Value("${amazon.aws.secretkey}")
    private String amazonAWSSecretKey;

    @Value("${amazon.aws.region}")
    private String amazonAWSRegion;

여기 내 App.java가 있습니다.

@SpringBootApplication
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
public class App {

//    private static final Logger logger = Logger.getLogger(App.class.toString());

    public static void main(String[] args){
        SpringApplication.run(App.class, args);
    }
}

스택 트레이스를 다음에 나타냅니다.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dynamoClientMapper' defined in file [C:\Users\ychen4\Desktop\DiningApplication\target\classes\main\java\com\dining\dao\DynamoClientMapper.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [main.java.com.dining.dao.DynamoClientMapper$$EnhancerBySpringCGLIB$$f4ba10ad]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: endpoint cannot be null
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1155) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1099) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at main.java.com.dining.App.main(App.java:18) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-1.5.2.RELEASE.jar:1.5.2.RELEASE]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [main.java.com.dining.dao.DynamoClientMapper$$EnhancerBySpringCGLIB$$f4ba10ad]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: endpoint cannot be null
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:154) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1147) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    ... 22 common frames omitted
Caused by: java.lang.IllegalArgumentException: endpoint cannot be null
    at com.amazonaws.util.RuntimeHttpUtils.toUri(RuntimeHttpUtils.java:182) ~[aws-java-sdk-core-1.11.125.jar:na]
    at com.amazonaws.util.RuntimeHttpUtils.toUri(RuntimeHttpUtils.java:171) ~[aws-java-sdk-core-1.11.125.jar:na]
    at com.amazonaws.AmazonWebServiceClient.toURI(AmazonWebServiceClient.java:238) ~[aws-java-sdk-core-1.11.125.jar:na]
    at com.amazonaws.AmazonWebServiceClient.setEndpoint(AmazonWebServiceClient.java:228) ~[aws-java-sdk-core-1.11.125.jar:na]
    at com.amazonaws.client.builder.AwsClientBuilder.setRegion(AwsClientBuilder.java:362) ~[aws-java-sdk-core-1.11.125.jar:na]
    at com.amazonaws.client.builder.AwsClientBuilder.configureMutableProperties(AwsClientBuilder.java:337) ~[aws-java-sdk-core-1.11.125.jar:na]
    at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46) ~[aws-java-sdk-core-1.11.125.jar:na]
    at main.java.com.dining.dao.DynamoClientMapper.<init>(DynamoClientMapper.java:32) ~[classes/:na]
    at main.java.com.dining.dao.DynamoClientMapper$$EnhancerBySpringCGLIB$$f4ba10ad.<init>(<generated>) ~[classes/:na]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_121]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_121]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_121]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_121]
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    ... 24 common frames omitted

다른 데이터베이스를 만들어 봤어요.그러나 Spring Boot에서는 그것도 인식되지 않습니다.내가 뭘 잘못하고 있지?

filepom.xml의 해 볼 수 .서 는 「」입니다.application.properties

<build>
  <resources>
    <resource>
      <directory>resources</directory>
      <targetPath>${project.build.outputDirectory}</targetPath>
      <includes>
        <include>application.properties</include>
      </includes>
    </resource>
  </resources>
</build>

자원 링크: https://stackoverflow.com/a/30595114/2293534

또 다른 접근법:

3.버전을 spring 3.X 버전을 추가할 수 .@PropertySource("application.properties")

@Configuration
@PropertySource(value = "classpath:application.properties")
public class ApplicationConfig {

    // more configuration ...
}

4 spring 4라는 새로운 하여 2개의 합니다.@PropertySources을 할 수 있습니다.@PropertySource★★★★

@PropertySources({
    @PropertySource("default.properties"),
    @PropertySource("overriding.properties")
})

상세한 것에 대하여는, https://stackoverflow.com/a/43659158/2293534 를 참조해 주세요.

업데이트 #1:

<고객명> 님의 App.java

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

//@SpringBootApplication
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }


    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(applicationClass);
    }

    private static Class<Application> applicationClass = Application.class;
}

★★★의 java.io.FileNotFoundException:

다음을 사용합니다.

@PropertySource(value = "database.properties", ignoreResourceNotFound = true)

업데이트 #2:

다음의 순서에 따라서, 애플리케이션을 실행하고 있습니다.정상적으로 실행됩니다.

  1. 에는 프로젝트 폴더가 .pom.xml가 존재합니다.

  2. .pom.xml두두확확 확다다다다다

  3. Run을 실행합니다.mvn clean

  4. 실행합니다.mvn clean install

  5. ★★★★★★★★★★★★★★★★★.mvn spring-boot:run

그러면 브라우저에서http://localhost:8080/

프로젝트가 정상적으로 열립니다.다른 페이지도 검색했습니다.

는 아래와 .http://localhost:8080/

여기에 이미지 설명 입력

http://localhost:8080/api/reviews

[
  {"id":1,"userName":"ychennay","reviewText":"This restaurant was terrific!"},{"id":2,"userName":"david","reviewText":"This restaurant
 was okay!"},
  {"id":3,"userName":"ben","reviewText":"This restaurant was
 mediocre!"},
  {"id":4,"userName":"leon","reviewText":"This restaurant
 was awful!"},
  {"id":5,"userName":"lawrence","reviewText":"This
 restaurant was confusing!"}
]

★★★★★★를 교환해 주세요.pom.xml

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.diningapp</groupId>
  <artifactId>Dining</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <properties>
    <jackson.version>2.7.5</jackson.version>
    <spring-version>4.3.7.RELEASE</spring-version>
    <dynamodb-local.port>8000</dynamodb-local.port>
    <dynamodb-local.endpoint>http://localhost:${dynamodb-local.port}</dynamodb-local.endpoint>
    <spring-boot-version>1.5.2.RELEASE</spring-boot-version>
    <aws-sdk-java-version>1.11.124</aws-sdk-java-version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>    <!-- For UTF-8 support -->
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>    <!-- For UTF-8 support -->
  </properties>

  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
          <source>1.7</source>          <!-- Used java7 -->
          <target>1.7</target>          <!-- Used java7 -->
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>${spring-boot-version}</version>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.0.0</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <repositories>
    <repository>
      <id>dynamodb-local-oregon</id>
      <name>DynamoDB Local Release Repository</name>
      <url>https://s3-us-west-2.amazonaws.com/dynamodb-local/release</url>
    </repository>
  </repositories>

  <dependencies>
    <dependency>
      <groupId>org.springframework.data</groupId>
      <artifactId>spring-data-releasetrain</artifactId>
      <version>Hopper-SR10</version>
      <type>pom</type>
      <!-- <scope>import</scope> -->
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <version>${spring-boot-version}</version>      <!-- You have missed to add this version -->
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-configuration-processor</artifactId>
      <version>${spring-boot-version}</version>      <!-- You have missed to add this version -->
      <optional>true</optional>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <version>${spring-boot-version}</version>
    </dependency>
    <dependency>
      <groupId>com.amazonaws</groupId>
      <artifactId>aws-java-sdk-dynamodb</artifactId>
      <version>${aws-sdk-java-version}</version>
    </dependency>
    <dependency>
      <groupId>com.github.derjust</groupId>
      <artifactId>spring-data-dynamodb</artifactId>
      <version>4.3.1</version>
    </dependency>

    <dependency>
      <groupId>com.amazonaws</groupId>
      <artifactId>aws-java-sdk-bom</artifactId>
      <version>${aws-sdk-java-version}</version>
      <type>pom</type>
      <!-- <scope>import</scope> -->
      <scope>provided</scope>      <!-- changed import to provided -->
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      <version>${spring-boot-version}</version>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>${spring-version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>${spring-version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>${spring-version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>${spring-version}</version>
    </dependency>
    <dependency>
      <groupId>jstl</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>${spring-version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>${jackson.version}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.38</version>      <!-- You have missed to add this version -->
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-security</artifactId>
      <version>${spring-boot-version}</version>
    </dependency>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.0.1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.16.10</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
</project>

오류 및 해결 방법:

문제 #1:

[WARNING] 'dependencies.dependency.scope' for org.springframework.data:spring-data-releasetrain:pom must be one of [provided, compile, runtime, test, system] but is 'import'. @ line 70, column 18

솔루션 1:

<dependency>
  <groupId>org.springframework.data</groupId>
  <artifactId>spring-data-releasetrain</artifactId>
  <version>Hopper-SR10</version>
  <type>pom</type>
  <!-- <scope>import</scope> -->
  <scope>provided</scope>  <!-- changed import to provided -->
</dependency>

문제 2:

[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-devtools:jar is missing. @ line 73, column 19

솔루션 2:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-devtools</artifactId>
  <version>${spring-boot-version}</version> <!-- You have missed to add this version -->
  <optional>true</optional>
</dependency>

제3호:

[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-configuration-processor:jar is missing. @ line 78, column 19

솔루션 3:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-configuration-processor</artifactId>
  <version>${spring-boot-version}</version> <!-- You have missed to add this version -->
  <optional>true</optional>
</dependency>

제4호:

[WARNING] 'dependencies.dependency.scope' for com.amazonaws:aws-java-sdk-bom:pom must be one of [provided, compile, runtime, test, system] but is 'import'. @ line 105, column 18

솔루션 4:

<dependency>
  <groupId>com.amazonaws</groupId>
  <artifactId>aws-java-sdk-bom</artifactId>
  <version>${aws-sdk-java-version}</version>
  <type>pom</type>
  <!-- <scope>import</scope> -->
  <scope>provided</scope> <!-- changed import to provided -->
</dependency>

문제 #5:

[ERROR] 'dependencies.dependency.version' for mysql:mysql-connector-java:jar is missing. @ line 148, column 19

솔루션 #5:

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>5.1.38</version> <!-- You have missed to add this version -->
</dependency>

@Enable 대신AutoConfiguration @Configuration을 다음과 같이 사용합니다.또한 prop 파일과 코드 이름([amazon.dynamodb.region vs amazon.aws.region])이 다르므로 aws 지역 속성을 수정해야 합니다.아래 변경 후 속성 파일 픽업을 시작하면 오류가 발생합니다.

@Configuration
@PropertySource("database.properties")
public class DynamoClientMapper {

    @Value("${amazon.dynamodb.endpoint}")
    private String amazonDynamoDBEndpoint;

    @Value("${amazon.aws.accesskey}")
    private String amazonAWSAccessKey;

    @Value("${amazon.aws.secretkey}")
    private String amazonAWSSecretKey;

    @Value("${amazon.aws.region}")
    private String amazonAWSRegion;

maven-pom이 다음 패키지를 사용하고 있는지 다시 확인하십시오.

<packaging>war</packaging>

로 설정되어 있는 경우pom또는 IDE가 모듈의 "봄" 특성을 인식하지 못할 수도 있습니다(IntelliJ 2018의 경우).

다음과 같은 접근방식을 시도했는가?

@Component
@PropertySource("database.properties")
public class DynamoClientMapper { ...}

또는

 @Service
 @PropertySource("database.properties")
 public class DynamoClientMapper { ...}

고정 경로를 사용할 수도 있습니다.

@PropertySource("파일:${C:/개발/워크스페이스/프로젝트/리소스/}/application.properties")

다른 속성 파일을 사용하려는 개발 프로세스에서 유용합니다.

또한 문제는 다음과 같은 의존성이 있다는 것입니다.spring-data-jpa종속성 계층에서 복제되므로 이 계층에서는 환경에 대해 2개의 서로 다른 프로파일이 있으며 앱을 실행할 때 실행자는 원하지 않는 환경 집합을 취합니다.

api("org.springframework.data", "spring-data-jpa", "2.3.4.RELEASE")

따라서 계층 내에 종속성 다운로드의 정의가 두 개 이상 존재하는 경우 프로젝트 모듈을 확인하는 것이 좋습니다.다시 나타나거나 중복된 것을 삭제할 필요는 없지만, 재동기화하고 스프링 러너가 원하는 환경 세트를 취하기 위해서는 주석과 주석 해제가 필요합니다.

  1. 코멘트 의존성
  2. 동기
  3. 비연결 의존성
  4. 동기
  5. 앱을 실행하다

그래들 물건

GL

비슷한 것을 발견했는데, 여기서 보듯이 application.properties 파일을 pom.xml에 추가함으로써 해결했습니다.https://maven.apache.org/plugins/maven-resources-plugin/examples/resource-directory.html

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <targetPath>${project.build.outputDirectory}</targetPath>
            <includes>
                <include>application.properties</include>
            </includes>
        </resource>
    </resources>

뭐가 효과가 있었는지 말해줄게.Spring Boot 의존성보다 JPA 의존성을 먼저 로드하고 있었는데, 바로 전환했더니 부팅이 되었습니다.pom.xml 내의 의존관계를 디세블로 하거나 순서를 변경합니다.

스프링 부트 1.x에서 2.x로의 (매우 늦은) 업그레이드의 경우:

resources/application.properties 외에 application.properties가 포함된 추가 디렉토리 위치를 사용합니다.

--spring.config.additional-location=.../

spring boot 1.x 대신 파일 이름을 사용하여 resources/application.properties와 spring.config.location을 모두 읽을 수 있습니다.

--spring.config.location=file:/...\myapplication.properties

스프링 부트 2.x에서는 여전히 spring.config.location이 인식되지만 더 이상 추가되지 않습니다.https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide#configuration-location 및 https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/boot-features-external-config.html를 참조하십시오.

언급URL : https://stackoverflow.com/questions/43818248/spring-boot-not-recognizing-application-properties-file

반응형