In the post Executing code on the creation or destruction of a bean in Spring I explain three ways to execute code on the creation or destruction of a Bean in Spring.
With two of these ways you can set the execution of a specific custom method:
- with the annotations @PostConstruct and @PreDestroy
- configuring the properties init-method and destroy-method
There is a very convenient way in the case that more beans have methods with the same name to be executed on their creation and destruction, i.e. you can specify a default method for all the beans.
Continue reading “How to set a default method to running code on the creation or destruction of a bean”
The @Autowired annotation is used to configure the dependency injection in Spring and is associated with a setter method, or a field or a constructor of a class.
In the case of a setter method or a field the bean used for dependency injection is chosen depending on the type. Continue reading “@Autowired and @Resource in Spring”
PropertyEditor is an interface that provides a support for the conversion of the value of a property (usually of type String) in an object that can be Date, URL, etc. Continue reading “PropertyEditors in Spring 3”
There are 3 ways to execute code to create a bean in Spring:
- with the annotation @PostConstruct
- implementing the interface InitializingBean
- configuring the property init-method
The reason why you run code when you create a bean is often to check the dependencies, and assign a default value, or automated actions such as starting a scheduled task.
The constructor of the bean may not be suitable for this purpose because the bean is not fully initialized until the constructor has not completed. Continue reading “Executing code on the creation or destruction of a bean in Spring”
In this post I explain how to implement Spring Security in a web application, as I did in a previous post but the authenticated user’s username and password are not saved to a file .xml but in a MySQL database.
As in the previous post, I configure one user only trying to access index.html and he is redirected to the standard login page for authentication.
In this project I configure log4j and maven too. Continue reading “Basic configuration of Spring Security 3 and MySQL”
In this post I write about a basic configuration of Spring Security 3, the Spring framework for authentication and authorization of the users.
In this example there is only one user trying to access to index.html and he is redirected to the standard login page for authentication.
In this project I use and configure maven and log4j too. Continue reading “Basic configuration of Spring Security 3”
MyBatis, a free software distributed under the Apache License 2.0, helps to connect Spring with relational databases using XML or annotations.
Continue reading “Setting MyBatis in Spring”
Here’s a simple example loading a jsp page to display data from a mysql table.
There are 2 ways to configure Log4j in Spring using:
- a .properties file
- a .xml file
The configuration with the. xml file allows to take advantage of some aspects that can not be configured with the .properties file that is therefore regarded as obsolete.
This article will explain how to configure Log4j using the .properties file and the configuration with .xml file will be treated in a subsequent article. Continue reading “Basic configuration of Log4j in Spring using a .properties file”