ctrl-F to open File/Replace Dialog check Regular Expressions Find: ^[\t }*@.*$\R Replace \with: <leave blank> Click Replace All
Intellij IDEA, JUnit, set JUnit version in test class
@RunWith(JUnit4.class) public class MainTest extends TestCase { ...
annotated Java Bean to read config.properties
This example is a little contrived in order to keep it simple. So far we have only covered Spring beans that are defined using the spring-config.xml. In this example we will use annotations in the bean class declaration to identify it as a Spring bean and then tell Spring where to look for these beans.... Continue Reading →
@Autowired and @Qualifier Annotations for Spring
We use @Autowired to automatically wire our bean dependencies. Example In the following example, we have autowired the home address for our student from the previous example. Spring will look for a single bean with a type that matches the type for home. If it finds this bean then it will automatically inject that bean... Continue Reading →
@Required Spring Annotation
@Required We use the @Required annotation to tell Spring that a property on a bean is required. Student.java Here we have applied the @Required annotation to the method setStudentId. student1.xml This will do nothing if we do not add the RequiredAnnotationBeanPostProcessor bean to our Spring config xml file. TestStudent1.java Now we can bring it all... Continue Reading →
Using a Bean PostProcessor for Spring Annotations
I will cover the easy way to do this in a later post, but in this post we will look at how Spring processes annotations. Available JSR-250 Spring Annotations The spring-beans-3.x.jar contains the package org.springframework.beans.factory.annotation. In this package you will find the following BeanPostProcessors: AutowiredAnnotationBeanPostProcessorInitDestroyAnnotationBeanPostProcessorQualifierAnnotationBeanPostProcessorRequiredAnnotationBeanPostProcesor These PostProcessors facilitate the following annotations which can be found... Continue Reading →
Spring Java Based Config
The following app-context.xml can be replaced with the following SpringConfig.java The MainApp.java code needs to be modified as follows: You will also need the CGLib jar This can be added in the Pom as follows: or downloaded from cglib.sourceforge.net
Spring Annotations @Qualifier or @Resource
What Doesn't Change app-context.xml Student.java What Changes Profile - using @Qualifier Profile - using @Resource
Spring Annotations
Annotations include: @Required @Autowired @Qualifier @Resource @PostConstruct @PreDestroy Autowired Annotations @AutoWired @AutoWired(required=false) @AutoWired @Qualifier("student1") @Resource(name="student1") AutoWired = required by default
Spring Bean Life Cycle
Initialization Callbacks Destruction Callbacks Initialization Callbacks public class Example1 implements InitializingBean { public void afterPropertiesSet() { } } <bean id="exampleBean" class="Example2" init-method="init"/> public class Example2 { public void init() { } } Destruction Callbacks public class Example1 implements DisposableBean { public void destroy() { } } <bean id="exampleBean" destroy-method="destroy"/> public class Example2 { public void... Continue Reading →