2017-10-07 14 views
0

저는 Spring 프로젝트를 개발 중입니다. 명령 줄에서 자격 증명을로드하고 싶지 않습니다. 나는이 Gradle을 명령을Grale 명령 줄에서 Spring 프로젝트 (Boot가 아님)에 인수를 전달할 수 없습니다.

gradlew build -Dspring.datasource.username=tester 

을 실행하기 위해 노력하고있어 나는 봄 프로젝트를 시동 할 때, 프로그램은 중단 점에서 중지와 나는 변수가 선언 여부를 참조하십시오. -D 대신 -P를 사용하려고 시도했지만 여전히 도움이되지 않습니다.

필자는 사용하려고 시도한 bmuschko 플러그인을 사용하여 스프링 응용 프로그램을 원격으로 배포하지만 성공하지는 못합니다. Spring에서 지원하는 System.getProperties() 및 Environment 객체를 사용하여 java 코드 속성을 검사했습니다.

gradlew cargoredeployremote -Dspring.datasource.username=tester 

응용 프로그램 속성이 성공적으로로드되었습니다.

중요 : 많은 튜토리얼을 만드는 방법을 보았지만 Spring Boot를 사용하여 Spring에서 선택된 구성 요소 만 사용합니다. 예 : http://nixmash.com/post/passing-arguments-to-spring-boot - bootRun 작업이 없기 때문에 제 경우에는 작동하지 않습니다.

아이디어가 있으십니까? 내 걸음에서 뭔가를 놓치고 있니? 명령에서 제공되는 $ 안에 이름을있는 application.properties에 {}이 다른했다 : 여기

group 'example' 
version '1.0.0' 


apply plugin: 'application' 
apply plugin: 'war' 
apply plugin: 'java' 
apply plugin: 'com.bmuschko.cargo' 
apply plugin: 'org.liquibase.gradle' 

compileJava.options.encoding = 'UTF-8' 

mainClassName = 'api.optic.config.WebAppInitializer' 
sourceCompatibility = 1.8 

buildscript { 
    repositories{ 
     jcenter() 
     mavenCentral() 
    } 
    dependencies{ 
     classpath 'com.bmuschko:gradle-cargo-plugin:2.2.3' 
     classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-RC3' 
     classpath 'org.liquibase:liquibase-core:3.4.1' 
     classpath "org.liquibase:liquibase-gradle-plugin:1.2.4" 
     classpath "mysql:mysql-connector-java:5.1.13" 
    } 
} 

project.ext { 
    springVersion = "4.3.6.RELEASE" 
    junitVersion = "5.0.0-RC3" 
} 

repositories { 
    mavenCentral() 
} 

dependencies { 

    compile "org.springframework:spring-core:${springVersion}" 
    compile "org.springframework:spring-context:${springVersion}" 
    compile "org.springframework:spring-context-support:${springVersion}" 
    compile "org.springframework:spring-beans:${springVersion}" 
    compile "org.springframework:spring-web:${springVersion}" 
    compile "org.springframework:spring-webmvc:${springVersion}" 
    compile "org.springframework:spring-orm:${springVersion}" 
    compile "org.springframework:spring-oxm:${springVersion}" 
    compile "org.springframework:spring-jdbc:${springVersion}" 
    compile "org.springframework:spring-test:${springVersion}" 
    compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.38' 

    compile group: 'javax.mail', name: 'javax.mail-api', version: '1.5.6' 


    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25' 
    compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.2' 

    compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-parameter-names', version: '2.9.0.pr2' 
    compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jdk8', version: '2.9.0.pr2' 
    compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.9.0.pr2' 
    compile 'javax.servlet:javax.servlet-api:3.1.0' 

    testCompile "org.junit.jupiter:junit-jupiter-api:${junitVersion}" 
    testRuntime("org.junit.jupiter:junit-jupiter-engine:${junitVersion}") 
} 

cargo { 
    containerId = 'tomcat8x' 
    port = 8080 

deployable { 
    context = 'example' 
} 

remote { 
    hostname = 'host.name.com' 
    username = 'tomcat' 
    password = 'pass' 
} 

답변

0

은 기본적으로이 문제

1 이름이 일치했다 내 build.gradle입니다 - 라인

솔루션 :

application.properties 
spring.datasource.username=${username} 

및 Gradle을 명령 줄에서

gradle build -Pusername=tester 

2 Gradle을 가진 도트 문제 :

gradle build -Pspring.datasource.username=tester 

를 넣을 수 없습니다 당신은 application.properties

의 경우에도
spring.datasource.username=${spring.datasource.username} 

예외가 발생했기 때문에

': processResources'작업을 실행하지 못했습니다.

'. \ src \ main \ resources \ application.properties'파일을 '. \ build \ resources \ main \ application.properties'로 복사 할 수 없습니다.

솔루션 :

점은 사용하는 대신에 _

gradle build -Pspring_datasource_username=tester 

및 응용 프로그램 속성에서 기호

spring.datasource.username=${spring_datasource_username}