javaspringspring-bootbazelapplication.properties

Bazel to read spring boot application.properties configurations


I have a very simple Spring Boot application that uses Maven and I'm trying to migrate it to use Bazel. I'm following the "Migrating from Maven to Bazel" tutorial and I've now the Spring Boot application running using Bazel.

The problem is that my application.properties (created in "src/main/resources") file is not being loaded by Spring, where I have setted up e.g. the port where my application runs.

My BUILD file is the following:

 java_library(
    name = "lib",
    srcs = glob(["*.java"]),
    #visibility = ["//src/test:__subpackages__"],
    deps = [
        "@maven//:org_springframework_boot_spring_boot",
        "@maven//:org_springframework_boot_spring_boot_autoconfigure",
        "@maven//:org_springframework_boot_spring_boot_starter_web",
    ],
)
java_binary(
    name = "app",
    main_class = "com.myapp.MyApplication",
    runtime_deps = [
        ":lib",
    ],
)

How can I achieve to load my application.properties file using Bazel?


Solution

  • To include data files like applications.properties in your JAR, use the resources attribute on the java_library or java_binary rule.

    https://docs.bazel.build/versions/master/be/java.html#java_library.resources

    Here's an example on its usage.