2016-05-23 5 views
2

Eclipseから起動したときにpostgresを正しくロードするスプリングブートプロジェクトがありますが、Windowsコマンドウィンドウで起動すると、テストデータベースがロードされます。cmd起動時のスプリングブート負荷テストデータベース

Iはjava -jar happy_list-0.1.0.jarとCMDからアプリケーションを起動すると、私はこのエラー(Iはスタックトレースの一部を除去する)を有する。java.lang.IllegalStateException:によって引き起こさ

をテストデータベース タイプのドライバ[HSQL java.lang.ClassNotFoundException::]によって引き起こされるクラスパス
では使用できませんorg.hsqldb.jdbcDriverなど

は、私はテストのための任意のテストや構成を持っていません。それは、いくつかの自動設定がスプリングブートによって行われなければなりませんが、なぜそれがeclipseまたはwindows cmdから実行されるときに異なって動作するのか分かりません。

PersistentContext:

@Configuration 
@EnableTransactionManagement 
@EnableJpaRepositories(basePackages = { "happy_listing" }) 
public class PersistentContext { 

} 

App.java:

@SpringBootApplication 
@EnableAutoConfiguration 
@Configuration 
@ComponentScan(basePackages = { "happy_listing" }) 
@Import({ PersistentContext.class }) 
public class App { 

    @Configuration 
    @PropertySource("classpath:application.properties") 
    static class ApplicationProperties { 
    } 

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

} 

Build.gradle:

buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.5.RELEASE") 
     classpath('se.transmode.gradle:gradle-docker:1.2') 
    } 
} 

group = 'marcandregirard' 

apply plugin: 'java' 
apply plugin: 'spring-boot' 
apply plugin: 'docker' 

jar { 
    baseName = 'happy_list' 
    version = '0.1.0' 
} 

springBoot { 
    mainClass = "happy_listing.App" 
} 
repositories { 
    mavenCentral() 
} 

dependencies { 
    compile 'org.slf4j:slf4j-api:1.7.13' 
    compile 'javax.ws.rs:javax.ws.rs-api:2.0' 
    compile 'org.springframework:spring-core' 
    compile 'org.springframework:spring-context' 
    compile 'org.springframework:spring-jdbc' 
    compile 'org.springframework.boot:spring-boot-starter-web' 
    compile group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.1.1' 
    compile 'org.springframework.data:spring-data-jpa:1.9.2.RELEASE' 
    compile 'org.hibernate:hibernate-entitymanager' 
    compile 'org.postgresql:postgresql:9.4-1206-jdbc42' 
    compile 'org.springframework:spring-web' 
    testCompile 'junit:junit:4.12' 
} 

task buildDocker(type: Docker, dependsOn: build) { 
    push = true 
    applicationName = jar.baseName 
    dockerfile = file('src/main/docker/Dockerfile') 
    doFirst { 
    copy { 
     from jar 
     into stageDir 
    } 
    } 
} 

私はにjarファイルと画像を作成するコマンドgradle build buildDockerとjarファイルを作成しましたDockerで実行します。

Eclipseの起動時にすべてうまく動作しています。

+0

他の情報が必要な場合や、正しくないものがある場合は、コメント内でそのように言います。 –

+0

また、あなたのjarファイルの隣にあるconfigフォルダに、外部の 'application.properties'や何かがないことを確認してください。 –

答えて

3

まず、適切なスターターを使用するすべての別々のjarファイルではなく、依存関係のクリーンアップを開始します。

dependencies { 
    compile 'javax.ws.rs:javax.ws.rs-api:2.0' 
    compile 'org.springframework.boot:spring-boot-starter-web' 
    compile 'org.springframework.boot:spring-boot-starter-data-jpa' 
    compile group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.1.1' 
    compile 'org.postgresql:postgresql:9.4-1206-jdbc42' 
    testCompile 'org.springframework.boot:spring-boot-starter-test' 
} 

次あなたは@SpringBootApplicationは、すでに他の3を意味し、春ブーツが既にapplication.propertiesをロードし、手動設定の多くをやろうとしているように見えます。それを削除する

@SpringBootApplication 
public class App { 

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

} 

PersistenceContextクラスは、既にSpringブートによって行われているように削除します。

クラスと依存関係をクリーンアップした後、古いクラスが残っていないことを確認してください。そのためには、Gradle cleanタスクを実行します。 gradle cleanはそのトリックを行うべきです。

したがって、クラスを削除するときには、gradle buildの代わりにgradle clean buildを必ず実行してください。

+0

きれいにしてくれてありがとう、すべてがまだEclipseで動作していて、はるかにクリーンです。まだ問題は解決されていますが、それ以上の情報は必要ですか? –

+0

コメントに記載されているように、この動作を引き起こす可能性のあるプロパティの 'application.properties'と環境変数もチェックしてください。 Springブートは特定の場所から 'application.properties'をロードします。 –

+0

奇妙な、私は私の設定パッケージに追加されたクラスDataBaseConfigを持っているが、私はそれが問題になるかもしれない日食で私のプロジェクトでそれを持っていない? –

関連する問題