Search code examples
springspring-bootopenrewrite

Recepie example for changing application.properties (or yaml) for a Spring Boot 3 application


a newbie to write recepies. What I'm going to try to accomplish is to read an application.properties (or yamal) file and convert values and entries to different ones. I've been searching around but can't really find a good example that I can look at.

For example:

spring:
  datasource:
    url: ${spring.datasource.url}
    username: ${spring.datasource.username}
    password: ${spring.datasource.password}

change to something like this:

spring:
  datasource:
    connectionString: ${spring.datasource.url}
    user: ${spring.datasource.username}
    pwd: ${spring.datasource.password}

So if anyone got something and can share it I'd appreciate it. Thanks Andy


Solution

  • Have you looked at the examples we have for other Spring properties?

    type: specs.openrewrite.org/v1beta/recipe
    name: org.openrewrite.java.spring.boot3.SpringBootProperties_3_3
    displayName: Migrate Spring Boot properties to 3.3
    description: Migrate properties found in `application.properties` and `application.yml`.
    tags:
      - spring
      - boot
    recipeList:
      - org.openrewrite.java.spring.ChangeSpringPropertyKey:
          oldPropertyKey: spring.couchbase.env.ssl.key-store
          newPropertyKey: spring.couchbase.env.ssl.bundle
    

    Taken from rewrite-spring/src/main/resources/META-INF/rewrite/spring-boot-33-properties.yml: https://github.com/openrewrite/rewrite-spring/blob/18f671d02ed987610b0a7203ff89aaae8143af1c/src/main/resources/META-INF/rewrite/spring-boot-33-properties.yml#L19-L29