How to load properties file in Spring / Various ways to load Properties file in Spring / Supply bean values from Properties file

Scenario

It is always advisable not to use configuration values inside your application code directly. Rather, supply them through configuration files which are external to the code. For Example, almost all applications involve database interaction wherein they connect to a database. Obviously there are database connection parameters such as database server url, database port etc. If they are hard-coded inside the code, then for every change in those parameters (suppose for a change in database server URL), the code will have to be touched. If they are supplied through an external properties file, then changing them would only require a restart of application or not even that in some cases. (more…)

Continue Reading

How to create bean in Spring / Various ways to create a bean in Spring / Create a bean in Spring without new keyword

Bean…What is it ?

A bean in java context is a simple java class which has some properties (also called fields) and their getter and setter methods. These properties can be regarded as instance variables of the bean. The name of the properties and their getter/setter methods should adhere to the JavaBeans specifications (should start with a small letter, should be camel-case and so on). (more…)

Continue Reading

How to send form fields from jsp to server in Spring MVC / How to submit a form to Spring Controller

Suppose we have a jsp page which has a form whose data should be sent to the server. The form has fields which are directly related to the fields of an entity on the server. An entity is a simple java class which has some fields and their getter and setter methods.
Let’s say the entity is a User (which means we have a User class on the server and each field of the jsp form is linked to a field of User class. When we say linked, it simply means that the name attribute of the form element is the same as the name of the corresponding entity field. (more…)

Continue Reading

How to perform custom initialization of beans in Spring / How to call a method before bean creation in Spring / Callback methods in Spring Beans

There are scenarios where we want to take some actions before a bean is fully constructed and put into service such as

  • giving a specific name to the bean other than that given in the configuration,
  • setting the application context into a bean property,
  • making a log entry immediately after bean initialization etc.
  • (more…)

Continue Reading
  • 1
  • 2
Close Menu