Submitted by admin on Mon, 05/23/2016 - 20:32
Factory design patterns help you create objects without using the new keyword directly within your code. The factory intern will create object for you. You can read more about factory pattern @ Factory Design Patterns.
Submitted by admin on Mon, 05/23/2016 - 19:56
This is a quick summary of important annotations in Spring for doing core tasks in Spring. Some of them might have already been covered in examples. Some of them might be covered later. Some of them might be a variation of the already covered ones, so please feel free to try them out and let us know if you face any issues.
You can use @Configuration to specify a Java configuration file.
Submitted by admin on Sun, 05/22/2016 - 22:37
If you invoke getBean("writer") and there are two beans defined with the name writer in your xml configuration file or Java configuration file. What will happen?
It will return the second one defined.
Submitted by admin on Sun, 05/22/2016 - 20:34
Creating a simple maven project using eclipse is very simple. Just a few clicks and you are done creating your first simple maven project. We will also quickly see some observations on the folders and files created by default after creating our simple project.
First, create a new Maven project using the eclipse new project wizard. You can either right click on the project explorer or go from the File menu item, to go to create new project wizard.
Submitted by admin on Mon, 05/16/2016 - 22:30
Through the autowiring feature, spring will intelligently guess some of the bean injection without needing to configure explicitly. Spring can do autowiring based on the type of the bean, name of the bean, and constructor of the bean. Default is autowire by type.
Submitted by admin on Sun, 05/15/2016 - 02:04
A Spring Boot standalone application uses the @SpringBootApplication annotation over a class with a main method that will execute the application. The SpringApplication.run method call accepts two parameters — the class that actually contains the annotated @SpringBootApplication annotation and any application arguments. The ApplicationArguments interface allows you to access any application arguments.
Submitted by admin on Sat, 05/14/2016 - 22:00
We can enable profiles from within a JUNIT test using @ActiveProfiles annotation. If you don't specify one, profile will be activated based on property value. This excercise writing JUNIT is applicable for code without profiles also: you just have to not activate any profiles.
Submitted by admin on Sat, 05/14/2016 - 21:14
We can use the property 'spring.profiles.active' within a properties file to activate a profile and is the most preferred approach.
In last note, we had seen enabling Spring profiles from the main method itself by calling getEnvironment().setActiveProfiles method on the AnnotationConfigApplicationContext object.
Submitted by heartin on Sat, 05/14/2016 - 13:13
@Profile annotation allow you to register components that will be selected only if its associated profile is active. You can selectively activate a set of beans in a class or all beans .
We will see how to do this using a Java configuration file using the @Profile annotation, and then we will also discuss about how to do it using XML configuration.
Important points about Spring Profiles
Submitted by heartin on Sat, 05/14/2016 - 09:07
We will create a simple class, configure it and test it. You can configure a Spring application through xml, or Java configuration or annotations along with xml or java configuration. In this example we will use @Component and @ComponentScan annotations along with Java configuration. Note that these annotations can also be used along with xml configuration and we will see how to do that in the end.