alexanoid
alexanoid

Reputation: 25790

Spring Boot/Maven property and system temp folder path

I have a following property declared at my Spring Boot/Maven project:

@Value("${download.folder.path}")
private String downloadFolderPath;

where download.folder.path is a property declared at my application.properties file and at Maven profile.

Right now the property value is something like this:

<download.folder.path>d:/somedir</download.folder.path>

Everything works fine but I want to point download.folder.path property to default system temp folder for my tests instead of providing a real path.

Is it possible with Spring/Maven configuration?

Upvotes: 1

Views: 10219

Answers (3)

Ashutosh Shukla
Ashutosh Shukla

Reputation: 555

1.)Writing below in SpringBoot main class for whole application to be working :

System.setProperty("java.io.tmpdir", "C:\\Users\\abcde\\Desktop\\Temp");

2.)While Running JUnit in Spring Boot application , I have set -Djava.io.tmpdir=C:\Work\TEMP in VM Arguments and it worked for me . enter image description here

Upvotes: 0

StanislavL
StanislavL

Reputation: 57381

Use reference to java tmp dir property (check System.getProperty("java.io.tmpdir")) and reference the property like this

<download.folder.path>{java.io.tmpdir}</download.folder.path>

See the reference properties here

Upvotes: 3

olan
olan

Reputation: 3638

If you are using Spring Boot, check out @TestPropertySource.

https://docs.spring.io/spring/docs/current/spring-framework-reference/html/integration-testing.html#__testpropertysource

You should be able to use that to point to /tmp or wherever.

Upvotes: 0

Related Questions