2016-06-22 31 views
5

Ho un piccolo problema con l'esecuzione della mia applicazione di avvio a molla nella finestra mobile.spring-boot non può essere avviato nella finestra mobile

stack: Maven 3+, avvio molla (JPA/riposo/pontile) - mysql - distribuire in finestra mobile

Così, ho avuto nel mio file pom

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

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <java.version>1.8</java.version> 
</properties> 

<dependencies> 
    <!-- SPRING BOOT 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-data-rest</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.projectlombok</groupId> 
     <artifactId>lombok</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
     <!-- add for exlude tomcat --> 
     <exclusions> 
      <exclusion> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-starter-tomcat</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <!-- END SPRING BOOT DEPENDENCIES--> 
    <!-- Jetty (tomcat replacement) --> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-jetty</artifactId> 
    </dependency> 
    <!-- mysql connector --> 
    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <scope>runtime</scope> 
    </dependency> 
    <!-- optional dependency javax.el --> 
    <dependency> 
     <groupId>javax.el</groupId> 
     <artifactId>javax.el-api</artifactId> 
     <version>3.0.0</version> 
    </dependency> 
    <!-- google http client --> 
    <dependency> 
     <groupId>com.google.http-client</groupId> 
     <artifactId>google-http-client</artifactId> 
     <version>1.21.0</version> 
    </dependency> 
    <!-- google http jackson --> 
    <dependency> 
     <groupId>com.google.http-client</groupId> 
     <artifactId>google-http-client-jackson2</artifactId> 
     <version>1.21.0</version> 
    </dependency> 
</dependencies> 

Ambiente: Ubuntu 16.04 x64 Il problema: localmente: provo a fare funzionare la mia applicazione con seguente comando nel terminale

user$ java -Xmx768m -jar /mnf-backend.jar --spring.datasource.url=jdbc:mysql://$MYSQL_PORT_3306_TCP_ADDR/app_1?autoReconnect=true&useSSL=false 
user$ #<--- LOOK AT THIS jvm has return of control with 1 status (or same status but not negative) 
:: Spring Boot ::    (v1.4.0.M3) # <--- spring boot starts by itself. HOW???? 

non è buono da posso tolerat e lui. Ma non docker. Quando i comandi sopra saranno eseguiti in finestra mobile allora contenitore arresto finestra mobile (perché -> uscita app con stato 1)

ENTRYPOINT ["java", "-Xmx768m", "-jar", "/mnf-backend.jar", "--spring.datasource.url=jdbc:mysql://$MYSQL_PORT_3306_TCP_ADDR/app_1?autoReconnect=true&useSSL=false"] 

Docker inizierà contenitore 1 secondo e interrompere immediatamente contenitore perché di ritorno a Java. Cerco un metodo che mi permetta di configurare l'app di primavera per un comportamento prevedibile o qualsiasi idea su come migliorare le istruzioni del docker. miei contenuti dockerfile:

FROM frolvlad/alpine-oraclejdk8:slim 

ENV MNFB_ENV production 
ENV SERVER_PORT 9000 

ADD ./builds/mnf-latest.jar mnf-backend.jar 

EXPOSE 9000 



ENTRYPOINT ["java", "-Xmx768m", "-jar", "/mnf-backend.jar", "--spring.datasource.url=jdbc:mysql://$MYSQL_PORT_3306_TCP_ADDR/minifinance?autoReconnect=true&useSSL=false"] 

tronchi docker di un contenitore enter image description here

Per esempio: quando ho iniziare nodejs controllo applicazione non tornare fino a quando l'applicazione non è finito

user$ node ./server.js 
[...here program output and stdout strings] 
[... it may be stopped by ctrl+c for example] 
+0

Puoi pubblicare il tuo Dockerfile che hai usato? E cosa non va bene che puoi tollerare? – techtabu

+0

scusa per il mio inglese. Voglio dire, posso tollerare questo comportamento di primavera localmente ma non nella finestra mobile –

+0

se l'app (java) esce con il codice di errore 1 - questo significa che hai alcuni problemi nell'ambiente, non Spring Boot. Cerca l'ID contenitore o il nome della finestra mobile e usa "logs docker per capire cosa è andato storto lì. – jdevelop

risposta

8

Penso che la problema è la e commerciale (&) nella riga di comando:

--spring.datasource.url=jdbc:mysql://$MYSQL_PORT_3306_TCP_ADDR/app_1?autoReconnect=true&useSSL=false"]

cercare di sfuggire esso:

--spring.datasource.url=jdbc:mysql://$MYSQL_PORT_3306_TCP_ADDR/app_1?autoReconnect=true\&useSSL=false"]

La e commerciale indica la shell per avviare il processo in background. Questo è esattamente ciò che accade sulla tua macchina locale. Se avvii il tuo jar, il processo dovrebbe iniziare in primo piano ... e il prompt non dovrebbe tornare direttamente.

0

Per farla semplice e pulito, abbiamo aggiunto le proprietà del database nei database.properties

mongo configurazione del database db

spring.data.mongodb.database=abc-auth 
spring.data.mongodb.host=192.168.2.2 
spring.data.mongodb.port=27017 
spring.data.mongodb.password=abc234quth 
spring.data.mongodb.username=abc-auth 

Spingiamo questo file durante l'esecuzione del Docker, in modo che solo le proprietà del database sarà ottenere l'override con l'applicazione esistente.proprietà

ENTRYPOINT ["java","-jar","/home/docker/service/abc.jar","--spring.config.location=application.properties"] 
Problemi correlati