1

I am in new to spring boot. I have created a web app using spring boot. My application require some properties file to do the processing. In eclipse What I do i set the path on Run configuration like bellow.

Bellow is the screen shot Now When I run the application I gets the require file on path and run smoothly. Now I want to deploy the war file on some server. How do i provide this path to my application.

Bellow is the project structure of my project. and files are here highlighted enter image description here

How do I set this file path using application.properties or any other way so that, I don't have to provide the path from run configuration, and the .war can be deploy on any server.

Update 1 : This what I tried. Created a customStart.bat content of the file is

set CATALINA_OPTS="-engine.home="/src/main/resources/" -Dlog4j.configuration=config/log4j.xml -Dlog4j.debug=true"
call startup.bat %CATALINA_OPTS%

But still that argument is not set. How do I do that?

Varun
  • 4,342
  • 19
  • 84
  • 119

2 Answers2

1

As an option you can add your properties to %tomcat_home%\conf\catalina.properties

Just put them at the end of the file as follows:

log4j.configuration=config/log4j.xml .....

Leffchik
  • 1,950
  • 14
  • 16
0

From spring boot official documentation (This is a highlight of the concept of creating custom spring boot variable) bellow you'll find a link to a Q/A that describes the solution.

Spring Boot jars are shipped with meta-data files that provide details of all supported configuration properties. The files are designed to allow IDE developers to offer contextual help and “code completion” as users are working with application.properties or application.yml files.

The majority of the meta-data file is generated automatically at compile time by processing all items annotated with @ConfigurationProperties. However, it is possible to write part of the meta-data manually for corner cases or more advanced use cases.

Configuration meta-data files are located inside jars under META-INF/spring-configuration-metadata.json They use a simple JSON format with items categorized under either “groups” or “properties” and additional values hint categorized under "hints":

Here is an example of a meta data config file :

{"groups": [
    {
        "name": "server",
        "type": "org.springframework.boot.autoconfigure.web.ServerProperties",
        "sourceType": "org.springframework.boot.autoconfigure.web.ServerProperties"
    },
    {
        "name": "spring.jpa.hibernate",
        "type": "org.springframework.boot.autoconfigure.orm.jpa.JpaProperties$Hibernate",
        "sourceType": "org.springframework.boot.autoconfigure.orm.jpa.JpaProperties",
        "sourceMethod": "getHibernate()"
    }
    ...
],"properties": [
    {
        "name": "server.port",
        "type": "java.lang.Integer",
        "sourceType": "org.springframework.boot.autoconfigure.web.ServerProperties"
    },
    {
          "name": "spring.jpa.hibernate.ddl-auto",
          "type": "java.lang.String",
          "description": "DDL mode. This is actually a shortcut for the \"hibernate.hbm2ddl.auto\" property.",
          "sourceType": "org.springframework.boot.autoconfigure.orm.jpa.JpaProperties$Hibernate"
    }
    ...
],"hints": [
    {
        "name": "spring.jpa.hibernate.ddl-auto",
        "values": [
            {
                "value": "none",
                "description": "Disable DDL handling."
            },
            {
                "value": "validate",
                "description": "Validate the schema, make no changes to the database."
            },
            {
                "value": "update",
                "description": "Update the schema if necessary."
            },
            {
                "value": "create",
                "description": "Create the schema and destroy previous data."
            },
            {
                "value": "create-drop",
                "description": "Create and then destroy the schema at the end of the session."
            }
        ]
    }
]}

Each “property” is a configuration item that the user specifies with a given value. For example server.port and server.servlet-path might be specified in application.properties as follows:

server.port=9090 server.servlet-path=/home The “groups” are higher level items that don’t themselves specify a value, but instead provide a contextual grouping for properties. For example the server.port and server.servlet-path properties are part of the server group.

Notes:

  • The groups section is note required
  • “hints” are additional information used to assist the user in configuring a given property. When configuring the spring.jpa.hibernate.ddl-auto property, a tool can use it to offer some auto-completion help for the none, validate, update, create and create-drop values.

You can easily generate your own configuration meta-data file from items annotated with @ConfigurationProperties by using the spring-boot-configuration-processor jar


You can check this Q/A

** for more details check the spring boot apendix section **

Abdelghani Roussi
  • 2,707
  • 2
  • 21
  • 39