3

Upgrade to Java Spring Boot Version 2.7.x on BTP

 1 year ago
source link: https://blogs.sap.com/2022/11/17/upgrade-to-java-spring-boot-version-2.7.x-on-btp/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

In this blog post i would like to share my experience on upgrading Java projects , BTP CAP Java projects migration to Spring Boot 2.7.5 version

Context

If you are going to upgrade your project

  • Then this may affect maven dependencies
  • Eventually compile, build issues
  • Java application may not start/Java application deployment issues runtime issues .

Java developers may some tough time in fixing depended on project source code or dependencies versions , how project packaged .

Below errors may be due to inconsistency in the Spring libraries of application.

 Error 1

creating bean with name ‘dataSource’ defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed

Error 2 :

Request processing failed; nested exception is com.sap.cds.CdsDataStoreException: Error executing the statement OUT Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table “CONFIGSERVICE_LOCATIONS” not found; SQL statement:

Error 3 :

org.springframework.boot.sql.init.dependency.AnnotationDependsOnDatabaseInitializationDetector.

Error 4 :

org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]:

Factory method ‘resourceHandlerMapping’ threw exception; nested exception is java.lang.NoSuchMethodError: ‘

io.github.classgraph.ClassGraph io.github.classgraph.ClassGraph.acceptPaths(j

… .. etc

Troubleshoot : Discovering the root causes of problems

  • If your application failed to start or unsuccessful deployment java app , then try to find Deployment errors locally by running  java app
mvn spring-boot:run
  • For Java project packaged as war file (Manifest.yml based ) If deployment failed on BTP then Download Java Deployment logs using
cf logs --recent yourjava-app-name
  • if Java project is one of module in MTA then you can refer below article

How to Download MTA Deployment Logs from SAP Business Technology Platform Cloud Foundry Environment

Solution

If your facing Deployment errors  or Spring Boot APPLICATION FAILED TO START

  • Please check that you consistently use Spring Boot 2.7.5 for all Spring Boot Modules and that you also included the correct Spring Framework version that is expected to be used by Spring Boot 2.7.5
  • Try to have all of these dependencies managed by the Spring Boot BOM and not maintain yourself.
  • Java Developers needs to analyse the dependency tree for project using commands or Eclipse IDE

Maven

For maven based projects you can get the list of dependent libraries by calling

mvn dependency:tree

mvn dependency:tree -Dincludes= org.springframework.*

  • Then fix versions . For example Spring Boot 7.5uses Spring Security 5.7.4 but application may have older version of Spring dependencies loaded form other dependencies (example : outdated SAP Cloud SDK bom downgraded the spring dependency to version 5.3.9. but spring-boot 2.7.5 requires a newer spring version. )
  • SAP also released the correspondingNotes

Please take a look inside the CAP release notes and the Spring Boot release notes where a solution for this exact issue is already mentioned.

  • Fixing dependencies issues will most likely resolve the Spring Boot start-up issues & migration issues

Always take a look at the release notes for all versions in between, as there might be important information in CAP release notes and the Spring Boot release notes

Topic2 : BTP Cloud Foundry Java Spring Services/REST API’s are not Loading Data from HANA Database , SQL Errors

If your Java apps connectivity to the HANA Cloud Database is broken & Deployment may fail

This issue is could be due to profile issues then solution is you have not maintain Active ProfileSpring Boot, default profile is set to default, you can set the profile via spring.profiles.active property.

In the spring boot application, there are several ways to set profiles (dev, uat, prod, etc.)

Few options are as follows

  • If you are using YML,then add below line
spring:

  config.activate.on-profile: cloud
  • If you are using properties file
spring.profiles.active=cloud
  • If it is SAP BTP Cloud Foundry Java Project

Then in manifest.yml file add below line under env

manifest.yml

env:

    SPRING_PROFILES_ACTIVE: cloud

    #For custom profile

    #JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{ enabled: false }'

After Deployment of APP , you can see new variable added in SAP  BTP user-provided variables

In your BTP Space of Java application

BTP-UserProvided.png

Or

you can also try to directly maintain

SPRING_PROFILES_ACTIVE  property in BTP Cockpit in your APP Space

Maintaining Active Profile over BTP Cockpit is quick fix

However, recommendation solution is to maintain spring active profile In source code

Thank you for reading this blog post. If you find this material useful or if you have any better suggestion to developers please leave your suggestions , feedback in the comments section below this may help Java Community on BTP

Feel free to also ‘Like’ ,‘Share’ , ‘Follow’ me to get new updates.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK