2017-09-12 124 views
1

我是新的春天,我有麻煩。 當我運行我的IntelliJ IDEA的一切應用都運行完美,但是當我把它編譯成一個.jar應用這個給我這個錯誤java.lang.IllegalArgumentException: Could not resolve placeholder 'jwt.secret' in value "${jwt.secret}"春季開機無法解析佔位符application.yml

這是我application.yml位於src/main/resources

#Config Application 
jwt: 
    header: Authorization 
    secret: mySecret 
    expiration: 604800 
    route: 
    authentication: 
     path: auth 
     refresh: refresh 
     token: check 

當我改變我對它的作品完美。

// @Value("${jwt.secret}") 
    @Value("mySecret") 
    private String secret; 

我做錯了什麼?

注:我使用Maven

這是我的pom.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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.example.test</groupId> 
    <artifactId>test-app</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>test-app</name> 
    <description>Test</description> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.5.6.RELEASE</version> 
     <relativePath/> <!-- lookup parent from repository --> 
    </parent> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
     <java.version>1.8</java.version> 
     <jjwt.version>0.7.0</jjwt.version> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-data-jpa</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-starter-web-services</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-data-rest</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.mobile</groupId> 
      <artifactId>spring-mobile-device</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
      <scope>runtime</scope> 
     </dependency> 
     <dependency> 
      <groupId>com.h2database</groupId> 
      <artifactId>h2</artifactId> 
      <scope>runtime</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-devtools</artifactId> 
      <optional>true</optional> 
     </dependency> 
     <dependency> 
      <groupId>io.jsonwebtoken</groupId> 
      <artifactId>jjwt</artifactId> 
      <version>${jjwt.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-configuration-processor</artifactId> 
      <optional>true</optional> 
     </dependency> 

    </dependencies> 

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


</project> 
+0

您是如何編譯的?你在使用maven嗎?這是一個春季啓動應用程序? – Ali

+0

試試這個, @ConfigurationProperties( 「智威湯遜」) 公共類CustomCacheConfiguration { @Value( 「$ {} jwt.secret」) 私人字符串祕密; ... } –

+0

我使用maven –

回答

0

我的糟糕的是我正在用Intellij Idea來構建。 使用此命令構建:

./mvnw clean package 
0

@Autowired 私人環境Env;

env.getProperty( 「jwt.secret」)

你可以試試!

+0

不是爲我工作:( –

+0

使用application.properties試試嗎? – wwj

相關問題