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.


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

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


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

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s