2017-09-12 1 views
1

Je suis nouveau au printemps et j'ai un problème avec cela. Quand je lance mon application avec IntelliJ tout idée fonctionne parfaitement, mais quand je compile à une application .jar cela me donne cette erreur java.lang.IllegalArgumentException: Could not resolve placeholder 'jwt.secret' in value "${jwt.secret}"Démarrage du printemps Impossible de résoudre l'espace réservé application.yml

Ceci est mon application.yml situé à src/main/resources

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

Quand je change Mon à ça ça fonctionne parfaitement.

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

Qu'est-ce que je fais mal?

Note: J'utilise MAVEN

Ceci est mon 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

Comment compilez-vous? Utilisez-vous maven? Est-ce une application de démarrage de printemps? – Ali

+0

Essayez ceci, @ConfigurationProperties ("JWT") CustomCacheConfiguration public class { @Value ("$ {} jwt.secret") secret chaîne privée ; ...} –

+0

J'utilise maven –

Répondre

0

Mon mauvais je construisais avec Intellij Idea. Construire en utilisant cette commande:

./mvnw clean package 
0

@Autowired env privé Environnement;

env.getProperty ("jwt.secret")

vous pouvez essayer!

+0

ne fonctionne pas pour moi :( –

+0

application.properties d'utilisation essayer? – wwj