搜索

6.2. Camel Spring Boot 应用程序的结构

download PDF

Camel Spring Boot 应用程序的目录结构如下:

  ├── LICENSE.md
  ├── pom.xml
  ├── README.md
  ├── configuration
  │   └── settings.xml
  └── src
      ├── main
      │   ├── jkube
      │   │   └── deployment.yml
      │   ├── java
      │   │   └── org
      │   │       └── example
      │   │           └── fis
      │   │               ├── Application.java
      │   │               └── MyTransformer.java
      │   └── resources
      │       ├── application.properties
      │       ├── logback.xml
      │       └── spring
      │           └── camel-context.xml
      └── test
          └── java
              └── org
                  └── example
                      └── fis

以下文件对于开发应用程序非常重要:

pom.xml
包括其他依赖项。与 Spring Boot 兼容的 Camel 组件在入门版本中可用,如 camel-jdbc-startercamel-infinispan-starter。启动者包含在 pom.xml 中后,它们会自动配置并在引导时使用 Camel 内容注册。用户可以使用 application.properties 文件配置组件的属性。
application.properties

允许您对配置进行外部化,并在不同的环境中使用相同的应用程序代码。详情请参阅 外部化配置

例如,在这个 Camel 应用程序中,您可以配置某些属性,如应用程序名称或 IP 地址等。

application.properties

#spring.main.sources=org.example.fos

logging.config=classpath:logback.xml

# the options from org.apache.camel.spring.boot.CamelConfigurationProperties can be configured here
camel.springboot.name=MyCamel

# lets listen on all ports to ensure we can be invoked from the pod IP
server.address=0.0.0.0
management.address=0.0.0.0

# lets use a different management port in case you need to listen to HTTP requests on 8080
management.server.port=8081

# disable all management endpoints except health
endpoints.enabled = false
endpoints.health.enabled = true

Application.java

它是运行应用程序的重要文件。作为用户,您将在此处导入 camel-context.xml 文件,以使用 Spring DSL 配置路由。

Application.java 文件指定 @SpringBootApplication 注释,它等同于 @Configuration@EnableAutoConfiguration@ComponentScan

Application.java

@SpringBootApplication
// load regular Spring XML file from the classpath that contains the Camel XML DSL
@ImportResource({"classpath:spring/camel-context.xml"})

它必须具有运行 Spring Boot 应用程序的主要方法。

Application.java

public class Application {
    /**
     * A main method to start this application.
     */
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

camel-context.xml

src/main/resources/spring/camel-context.xml 是开发应用程序的重要文件,因为它包含 Camel 路由。

注意
src/main/jkube/deployment.yml

提供与 openshift-maven-plugin 生成的默认 OpenShift 配置文件合并的额外配置。

注意

此文件不是 Spring Boot 应用程序的一部分,但它用于限制 CPU 和内存用量等资源。

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.