Read properties values in Java Spring Controller

To configure the environmental parameters, we read the values from property files. I have a controller which upload the files. The uploaded files will be saved in a location, which is defined in a property file. In this example I shall show you how to read the location name from the property file.

[code language=”java”]

@Controller
@PropertySource(“classpath:app.properties”)
public class FileUploadController {
@Value(“${upload.Folder}”)
String uploadFolder;
}

[/code]

I have defined the property in app.properties file which is saved in src folder (or any other path defined in classpath.

[code language=”java”]

upload.Folder=C:\\vss\\upload

[/code]

Thats it! The variable uploadFolder will be assigned using the values given by app.properties.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top