I am facing a issue in reading an additional property file
src/main/resources/default.properties
from
META-INF/batch/jobs-infra.xml.
I have followed the instructions given in - load external config file in spring batch admin. But not sure the location where I placed the files.
Please, check my application folder structure attached for your reference. I need a help on this.
Related
I need your help on two issues :
1// I have a spring batch app that has this application.properties file :
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.datasource.url=jdbc:oracle:xxxxxxxx
ClassApp=xxxx
Country=xxxxx
spring.batch.initialize-schema=always
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
CRON_EXPRESSION=xxxxx
I want to externalize this configuration to an external file in a specific location and pass it then in the jvm when i run the final jar generated by my application.
Because the jar will be run on a centos machine later and all the variables in the properties file should get their values from that external file !!
How can i do this ?
2// Also, i have some log feature in my app like this one :
log.debug("CreateQuartzJob is running......");
But i want to externalize application logs to an external file also with all execution details too.
How can i make these two features pleaaase ?
Thank you for help :)
As for external configuration, you can use the "additional-location" argument when running your application. Just create a properties or yaml file, e.g., application.yml, and run your jar like this:
java -jar myJar.jar
--spring.config.additional-location=file:/some/directory/application.yml
I am trying override few of the properties in my spring boot application. The properties are spread across mutiple yml files within the same directory and hence i would like to specify spring.config.additional-location parameter with the value of directory..
spring.config.additional-location=file:///Mydirectory/
But the application is not able to load the configs. If I explicitly specify the file name, the properties are getting overwritten
spring.config.additional-location=file:///Mydirectory/application.yml
Is it possible to load all the files available in a directory using spring.config.additional-location? If yes, please let me know
I am new to Spring framework in spring site There is tutorial at https://spring.io/guides/gs/uploading-files/ that upload file to the root folder "upload-dir" (this folder is beside src root folder)
questions:
How can I access and show image in browser (or access it in thymeleaf by th:src="#{}" syntax) -
by browsing to localhost:8080/files/first.jpg because of controller it give me download link.
should I always upload file to folder that beside src folder for example I want to upload file to "src/main/resources/static/file" is it possible?
When accessing files in your code, Spring will (by default) assume that the src/main/resources is the parent directory. If you are planning on accessing the files that are uploaded, then I would use src/main/resources (or a subdirectory of this location) as the upload path. This way, you can simply access them in Thymeleaf as such:
Location: src/main/resources/picture.jpg
Thymeleaf: th:src="#{picture.jpg}"
Or if the file exists in a subdirectory:
Location: src/main/resources/somedir/picture.jpg
Thymeleaf: th:src="#{somedir/picture.jpg}"
If you are storing the file(s) elsewhere, then you can also access them using various prefixes like classpath or file, i.e.:
classpath:com/myapp/config.xml
See more about Resources in Spring here:
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/resources.html
Hope this helps!
Where can i store SLF4J configuration file so that all production and test environment may have access to it? I want to store the config file outside of the web app at an arbitrary location and retrieve that location upon startup. I also want to allow for changing location of the config file so no classpath. Im thinking about using getters and setters to retrieve the file path.
Any ideas??
slf4j is (for all practical purposes) just the API. You need a backend which does the actual work.
If you use logback you can ship a logback.xml file with your application which just includes another file. If I recall correctly the filename string can hold a ${variable} which you can then define outside your application.
See https://logback.qos.ch/manual/configuration.html#configFileProperty
You may specify the location of the default configuration file with a system property named "logback.configurationFile". The value of this property can be a URL, a resource on the class path or a path to a file external to the application.
java -Dlogback.configurationFile=/path/to/config.xml chapters.configuration.MyApp1
We are using neo4j 1.9.5 in embedded mode in a webapp and I would like to configure logback for it.
I've seen that the class org.neo4j.kernel.logging.LogbackService reads a neo4j-logback.xml file from the classpath, so I was able to configure neo4j logging that way.
But what I would like to be able to do is point neo4j to a logback.xml file on location on disk, so I can put the config somewhere outside our webcontainer, is such a thing possible?
Its not possible. Because in init method in org.neo4j.kernel.logging.LogbackService class they using
URL resource = getClass().getClassLoader().getResource( logbackConfigurationFilename );
to read the config file. So they config file must be in the classpath.You cannot point some other disk location.