abi*_*eez 5 spring-mvc cloud-foundry spring-boot
我尝试使用以下内容将我的Spring启动应用程序部署到CF. pom.xml
<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>
Run Code Online (Sandbox Code Playgroud)
更新
我的应用程序
@SpringBootApplication
public class EdollarApplication {
@Autowired
private DataSource dataSource;
public static void main(String[] args) {
SpringApplication.run(EdollarApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
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);
}
}
Run Code Online (Sandbox Code Playgroud)
日志中没有错误,但是我无法访问我在应用程序中定义的URL.示例日志如下所示
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
Run Code Online (Sandbox Code Playgroud)
我在这里想念的是什么?
下面是一个最小的Spring Boot项目示例,该项目配置为在Cloud Foundry中运行:https://github.com/gratiartis/super-mini
我将它放在Cloud Foundry中,将以下内容manifest.yml放入项目的根目录中.
---
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
Run Code Online (Sandbox Code Playgroud)
请注意,可以添加以下内容以激活配置文件(即"云"):
env:
SPRING_PROFILES_ACTIVE: cloud
Run Code Online (Sandbox Code Playgroud)
这path是基于我从项目的根目录运行部署.我确信你会猜到,它是一个Maven构建,因此在target目录中创建.jar .
要部署cd到项目的根目录并运行:
cf push
Run Code Online (Sandbox Code Playgroud)
以上将创建一个运行在http://super-mini.cfapps.io/hello的应用程序
看一看 - 它正在运行.当然,我现在已经创建了该应用程序名称,因此您无法使用它!
| 归档时间: |
|
| 查看次数: |
6907 次 |
| 最近记录: |