2015-05-06 18 views
5

Ho provato a schierare la mia primavera di avvio app per CF con il seguente pom.xmlCome distribuire Spring Boot su Cloud Foundry?

 <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.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>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
      <scope>runtime</scope> 
     </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.boot</groupId> 
      <artifactId>spring-boot-starter-cloud-connectors</artifactId> 
     </dependency> 
    </dependencies> 

AGGIORNATO

La mia applicazione

@SpringBootApplication 
public class EdollarApplication { 

    @Autowired 
    private DataSource dataSource; 

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

DataSourceConfiguration.java

@Configuration 
@Profile("cloud") 
public class DataSourceConfiguration { 

    @Bean 
    public Cloud cloud() { 
    return new CloudFactory().getCloud(); 
    } 

    @Bean 
    @ConfigurationProperties(DataSourceProperties.PREFIX) 
    public DataSource dataSource() { 
    return cloud().getSingletonServiceConnector(DataSource.class, null); 
    } 

} 

Non ci sono errori nei registri, ma non sono in grado di accedere agli URL che ho definito nell'applicazione. Esempi di log riportati sotto

Updated app with guid 8b167ac9-11bb-483e-be0a-3dd8c8991a84 ({"state"=>"STARTED"}) 
-----> Downloaded app package (20K) 

-----> Downloading Open Jdk JRE 1.8.0_45 from https://download.run.pivotal.io/openjdk/trusty/x86_64/openjdk-1.8.0_45.tar.gz (2.5s) 
     Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (1.3s) 
-----> Downloading Tomcat Instance 8.0.21 from https://download.run.pivotal.io/tomcat/tomcat-8.0.21.tar.gz (0.5s) 
     Expanding Tomcat to .java-buildpack/tomcat (0.1s) 
-----> Downloading Tomcat Lifecycle Support 2.4.0_RELEASE from https://download.run.pivotal.io/tomcat-lifecycle-support/tomcat-lifecycle-support-2.4.0_RELEASE.jar (0.0s) 
-----> Downloading Tomcat Logging Support 2.4.0_RELEASE from https://download.run.pivotal.io/tomcat-logging-support/tomcat-logging-support-2.4.0_RELEASE.jar (0.0s) 
-----> Downloading Tomcat Access Logging Support 2.4.0_RELEASE from https://download.run.pivotal.io/tomcat-access-logging-support/tomcat-access-logging-support-2.4.0_RELEASE.jar (0.0s) 
-----> Uploading droplet (51M) 
[CONTAINER] org.apache.catalina.core.StandardService   INFO Starting service Catalina 
[CONTAINER] org.apache.catalina.startup.Catalina    INFO Initialization processed in 514 ms 
[CONTAINER] org.apache.coyote.http11.Http11NioProtocol   INFO Initializing ProtocolHandler ["http-nio-61187"] 
[CONTAINER] org.apache.catalina.core.StandardEngine   INFO Starting Servlet Engine: Apache Tomcat/8.0.21 
[CONTAINER] org.apache.catalina.startup.HostConfig    INFO Deploying web application directory /home/vcap/app/.java-buildpack/tomcat/webapps/ROOT 
[CONTAINER] org.apache.jasper.servlet.TldScanner    INFO At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 
[CONTAINER] org.apache.coyote.http11.Http11NioProtocol   INFO Starting ProtocolHandler ["http-nio-61187"] 
[CONTAINER] org.apache.tomcat.util.net.NioSelectorPool   INFO Using a shared selector for servlet write/read 
[CONTAINER] org.apache.catalina.startup.Catalina    INFO Server startup in 507 ms 

Cosa mi sono perso qui?

+0

Probabilmente vale la pena confermare ... È 'EdollarApplication' in un pacchetto radice chiamato' demo'? E funziona sulla riga di comando? ad esempio 'java-jar - .jar'? – Steve

+0

Probabilmente non il problema, ma non è necessario '@ EnableAutoConfiguration' nella tua classe principale. – Steve

+0

C'è qualche esempio di 'Spring Boot' per lavorare fuori dalla scatola o con una configurazione minima in Cloud Foundry? – abiieez

risposta

6

Ecco un esempio di un progetto minimal Primavera di avvio che è configurato per l'esecuzione in Cloud Foundry: https://github.com/gratiartis/super-mini

ho preso in esecuzione in Cloud Foundry mettendo il seguente manifest.yml nella directory principale del progetto.

--- 
applications: 
- name: super-mini 
    # Fork of https://github.com/cloudfoundry/java-buildpack 
    # For stability, keep your own fork. 
    buildpack: https://github.com/gratiartis/java-buildpack 
    memory: 512M 
    instances: 1 
    # Because the URL will be http://super-mini.cfapps.io/ 
    host: super-mini 
    domain: cfapps.io 
    path: target/super-mini-1.0.0-SNAPSHOT.jar 

Nota che il seguente può essere aggiunto a attivare un profilo (vale a dire "nuvola"):

env: 
    SPRING_PROFILES_ACTIVE: cloud 

Il path si basa su di me che esegue il deploy dalla directory principale del mio progetto. Come sono sicuro avrete intuito, è una build Maven, quindi un .jar viene creato in una directory target.

Per distribuire, cd nella directory principale del progetto ed eseguire:

cf push 

È possibile che questo creerà un'applicazione in esecuzione a http://super-mini.cfapps.io/hello

Date un'occhiata - è in esecuzione al momento. Certo, ora ho creato il nome dell'applicazione, quindi non puoi usarlo!

+0

Devo usare mysql come nome del profilo come il tuo? O ho bisogno di cambiarlo in 'Cloud' come in' DataSourceConfiguration' sopra. – abiieez

+0

Ho seguito esattamente quello che mi hai suggerito. L'applicazione è stata inviata al cloud, ma non sono in grado di accedere a nessuno degli URL. Infatti nei log non vedo alcuna mappatura richiesta è stata mappata. – abiieez

+0

Oh no ... Ho solo un 'application.yml' nella cartella delle risorse dell'applicazione con un profilo chiamato' mysql', che definisce i dettagli della connessione.È stato un modo semplice per farlo funzionare, ma il materiale di Spring Cloud sarà probabilmente migliore. – Steve