2016-04-08 15 views
54

Trong dự án maven, tôi cố gắng thay thế một số mã thông báo bằng cách sử dụng lọc tài nguyên maven nhưng nó không hoạt động. Tôi có một số dự án khác hoạt động nhưng không hoạt động trong dự án đơn lẻ này không chắc chắn những gì là sai.Lọc tài nguyên Maven không hoạt động - vì phụ thuộc khởi động mùa xuân

Các tập tin bất động sản đang trong /src/main/resources/my.properties vị trí

tôi đã cố gắng lệnh maven khác nhau như dưới đây nhưng không hoạt động.

mvn clean install 
mvn clean install resources:resources 

my.properties

### Spring boot properties 
jdbc.url=${jdbc.url} 
ldap.domain=${ldap_domain} 
ldap.url=${ldap_url} 

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.jai</groupId> 
    <artifactId>client</artifactId> 
    <version>0.0.6-SNAPSHOT</version> 
    <name>client</name> 
    <description>client web application</description> 
    <packaging>war</packaging> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.3.2.RELEASE</version> 
     <relativePath /> 
    </parent> 


    <dependencies> 

     <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-tomcat</artifactId> 
      <scope>provided</scope> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-ldap</artifactId> 
     </dependency> 

    </dependencies> 

    <build> 
     <finalName>client</finalName> 

     <resources> 
      <resource> 
       <directory>src/main/resources</directory> 
       <filtering>true</filtering> 
      </resource> 
     </resources> 

     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 

      <plugin> 
       <artifactId>maven-war-plugin</artifactId> 
       <configuration> 
        <warSourceDirectory>WebContent</warSourceDirectory> 
        <failOnMissingWebXml>false</failOnMissingWebXml> 
       </configuration> 
      </plugin> 

      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>exec-maven-plugin</artifactId> 
       <executions> 
        <execution> 
         <id>exec-bower-install</id> 
         <phase>generate-sources</phase> 
         <configuration> 
          <executable>bower</executable> 
          <arguments> 
           <argument>install</argument> 
          </arguments> 
         </configuration> 
         <goals> 
          <goal>exec</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 

     </plugins> 

    </build> 


    <profiles> 
     <!-- localhost environment --> 
     <profile> 
      <id>local</id> 

      <activation> 
       <activeByDefault>true</activeByDefault> 
      </activation> 

      <properties> 

       <ldap_domain>mydomain.local</ldap_domain> 
       <ldap_url>ldap://server:389</ldap_url> 
       <jdbc.url>testttttttttttttttttttttt</jdbc.url> 

      </properties> 
     </profile> 

     </profiles> 

</project> 

Cập nhật: -

tôi đã tìm ra này vấn đề là do phụ thuộc khởi động mùa xuân. Nếu tôi nhận xét phần <parent> và các phụ thuộc khởi động mùa xuân khác, thì nó hoạt động tốt và có thể thay thế mã thông báo. Nhưng vẫn không chắc chắn làm thế nào để khắc phục điều này bằng cách giữ khởi động mùa xuân.

+2

Có vẻ đây là một khiếm khuyết trong https khởi động mùa xuân: //github.com/spring-projects/spring-boot/issues/980 – Jay

+0

vẫn là một vấn đề với khởi động mùa xuân 1.5.9.RELEASE – jediz

Trả lời

113

Cuối cùng, tìm thấy câu trả lời từ liên kết trong nhận xét của tôi. Vì đây là một ứng dụng khởi động mùa xuân ... trường hợp đặc biệt ... các ký hiệu nên

@[email protected] instead of ${xxxxx} 

Vì vậy, tập tin bất động sản của tôi sẽ là như sau

### Spring boot properties 
[email protected]@ 
[email protected][email protected] 
[email protected][email protected] 
+4

Bạn có thêm thông tin về điều đó trong https://docs.spring.io/spring-boot /docs/current/reference/html/howto-properties-and-configuration.html – pedrocgsousa

+0

Chỉ để giữ cho mọi người khỏi săn bắn, điều này đã được thay đổi trong SB 1.3.0. Đây là https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.3-Release-Notes#maven-resources-filtering – mdo123

+0

Điều này làm cho ngày của tôi ;-) Cảm ơn rất nhiều! – pixelstuermer

Các vấn đề liên quan