Skip to content

Upgrading Components to Spring Boot

mmackaysearch edited this page Sep 29, 2021 · 6 revisions

Step 1) Update pom.xml to current dependencies, at the time of writing version numbers are:

  • spring-boot-version: 2.5.2
  • camel-version: 3.11.0
  • cxf-version: 3.4.4
  • cxf-boot-starter-version: 3.4.4
  • spring-version: 5.3.8
  • xmlunit-version: 1.6
  • commons-lang-version: 3.12.0

Modify the version of the bundle at the top and change the "bundle" configuration to "war".

Update the version ranges of the OJB shared common bundles.

Next include these Spring Boot Dependencies before your <dependencies> tag: <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring-boot-version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-spring-boot-dependencies</artifactId> <version>${camel-version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>

Also include all these dependencies under your tag: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-saxon</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-undertow</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-actuator</artifactId> </dependency> <!-- Camel --> <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-spring-boot</artifactId> </dependency> <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-spring-boot-xml-starter</artifactId> </dependency> <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-stream-starter</artifactId> </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-api</artifactId> </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-core-xml</artifactId> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxws</artifactId> <version>${cxf-boot-starter-version}</version> </dependency>

As well as: org.springframework.boot spring-boot-starter-test test

	 <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.junit.platform/junit-platform-launcher -->
    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-launcher</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.junit.vintage</groupId>
        <artifactId>junit-vintage-engine</artifactId>
        <scope>test</scope>
    </dependency>

As well as:

<dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxws</artifactId> <version>${cxf-boot-starter-version}</version> </dependency>

Common Dependencies to Modify:

  • camel-quartz2 to camel-quartz
  • camel-http4 to camel-http
  • camel-test-spring3 to camel-test-spring-junit5
  • commons-lang to commons-lang3 (artifactID is also now org.apache.commons)

Delete all versions in dependencies where there is a yellow error, and delete the log4j dependency.

Under the <plugins> tab include this block: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.2.2</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin>

As well as <finalName>${artifactId}</finalName>

Step 2: Create an Application.java class

In src/main/java create an Application.java class (typically named after the bundle being upgraded) and include these annotations to the class where package path is the package location:

@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class, `HibernateJpaAutoConfiguration.class}) @ComponentScan({"PACKAGE_PATH"}) @ImportResource(value = {"classpath:META-INF/spring/camel-context.xml", "classpath:META-INF/spring/cxf-endpoints.xml", "classpath:META-INF/spring/beans.xml", "classpath:META-INF/spring/dev-beans.xml"})

And modify the main method to this where CLASS_NAME is the name of the class:

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

If you are working on an intermediary component, you may require an additional Properties.class class within src/main/java. If that is the case the class definition would look like this:

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

The Properties.class file would look like this:

@Component @ConfigurationProperties(prefix = "PREFIX_NAME") public class CLASS_NAME { private String dbAuditLog = "false";

public String getDbAuditLog() {
	return dbAuditLog;
}

public void setDbAuditLog(String dbAuditLog) {
	this.dbAuditLog = dbAuditLog;
} 

}

Then Ctrl-Shift-O (if in Eclipse) to import all the proper libraries needed.

Step 3: Create a beans.xml file from the existing camel-context.xml file.

Copy all of the nodes with the tag from the camel-context.xml file and place them in the beans.xml.

If the bundle is an intermediary add this bean:

Step 4: Create an application.properties and an application-dev.properties file.

Within application.properties put these commands:

spring.main.allow-bean-definition-overriding=true cxf.path=/OJB

Within application-dev.properties, copy the info in the PROJECT_NAME.cfg file into that file exactly the same as it is present within the config file.

Step 5: Fix existing JUnit Tests.

In any test where there is an instance of camel-context being run, have these annotations preface your class declaration:

  • @CamelSpringBootTest
  • @SpringBootTest(classes=APPLICATION_CLASS_NAME.class)
  • @ActiveProfiles("dev")
  • @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
  • @UseAdviceWith

Then a simple Ctrl-Shift-O should resolve any import errors.

Additionally make sure to delete the existing @Test annotation import and replace it with the Jupiter version, otherwise it is possible some of the JUnit tests may not run properly.

Lastly, change any existing adviceWith() method calls to follow this syntax using a lambda expression:

AdviceWith.adviceWith(context, ROUTE_NAME, route -> { route.METHOD_CALL; });

Step 6: Modify the camel-context.xml file

Replace any tag with the parameter "headerName" to just "name". Replace any method tag with the parameter "bean" to just "ref". Replace any "property." to "exchangeProperty.".

For intermediaries: Replace "groupExchanges="true" with "strategyRef="groupedExchangeAggregationStrategy". Replace "completionTime" and "completionSize" with "completionTimeExpression" and "completionSizeExpression", respectively.

(Additional Step Only for Intermediaries): Create a dev-beans.xml file from the existing extensible-beans.xml file.

Modify the top header by adding the parameter profile="dev".

Modify the existing bean declaration by removing the external constructor-arg tags and put the id of the most external bean within the second most external bean declaration. Similarly if there are any <util-map> declarations.

Step 8: Modify dao.xml (if it exists):

Replace "maxActive" in dataSource to "maxTotal".

Step 9: Remove CXF Endpoints Inbound ClientAuthHttpSettings.

Step 10: Run the JUnit tests to ensure there are no errors.

It is possible that there may need to be more work on the AdviceWith methods, this is very situational but generally if there is any mocking the method interceptSendToEndpoint() will typically not work, the method weaveById will serve that purpose for static mocking.

Clone this wiki locally