Spring bean reference example

In Spring, beans can “access” to each other by specify the bean references in the same or different bean configuration file. 1. Bean in different XML files If you are referring to a bean in different XML file, you can reference it with a ‘ref‘ tag, ‘bean‘ attribute. <ref bean="someBean"/> In this example, the bean …

Read more

How to inject value into bean properties in Spring

In Spring, there are three ways to inject value into bean properties. Normal way Shortcut “p” schema See a simple Java class, which contains two properties – name and type. Later you will use Spring to inject value into the bean properties. package com.mkyong.common; public class FileNameGenerator { private String name; private String type; public …

Read more

How to install Spring IDE in Eclipse

Spring IDE is a very useful graphical user interface tool adding support for Spring Framework. In this tutorial, we show you two ways to install Spring IDE in Eclipse. Version used in this tutorial : Spring IDE 2.9 Eclipse 3.7 Spring IDE or SpringSource Tool Suite (STS)? Refer to this Spring IDE vs STS pdf …

Read more

Spring loosely coupled example

The concept of object-oriented is a good design to break your system into a group of reusable objects. However, when system grows larger, especially in Java project, the huge object dependencies will always tightly coupled causing objects very hard to manage or modify. In this scenario, you can use Spring framework to act as a …

Read more

How to load multiple Spring bean configuration file

Problem In a large project structure, the Spring’s bean configuration files are located in different folders for easy maintainability and modular. For example, Spring-Common.xml in common folder, Spring-Connection.xml in connection folder, Spring-ModuleA.xml in ModuleA folder…and etc. You may load multiple Spring bean configuration files in the code : ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"Spring-Common.xml", …

Read more

Maven + Spring hello world example

This quick guide example uses Maven to generate a simple Java project structure, and demonstrates how to retrieve Spring bean and prints a “hello world” string. Technologies used in this article : Spring 2.5.6 Maven 3.0.3 Eclipse 3.6 JDK 1.6.0.13 Spring 3 example For Spring 3, refer to this Maven + Spring 3 hello world …

Read more

Spring AOP Interceptor transaction is not working

Problem The Spring AOP transaction is not working in following interceptors? <bean id="testAutoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="interceptorNames"> <list> <idref bean="urlInterceptorInsert" /> <idref bean="urlInterceptorCommit" /> <idref bean="urlInterceptorRelease" /> <idref bean="matchGenericTxInterceptor" /> </list> </property> <property name="beanNames"> <list> <idref local="urlBo" /> </list> </property> </bean> The “matchGenericTxInterceptor” transaction interceptor, suppose to intercept urlInterceptorInsert, urlInterceptorCommit,urlInterceptorRelease, but it’s not work as expected? …

Read more