View RSS Feed

All Blog Entries

  1. More AOP in Spring Part 2

    by , 11-16-2011 at 05:26 PM
    Along with aspect’s advice, pointcuts, which are used to pinpoint where an aspect’s advice should be applied, are considered among the most fundamental elements of an aspect. In Spring AOP, we define pointcuts using AspectJ’s pointcut expression language. If you’re already know AspectJ, then defining pointcuts in Spring should feel natural. Otherwise, I will provide you with quick tips that will help you with writing AspectJ-style pointcuts.

    In Spring AOP, the key thing to remember ...
    Tags: aop, spring aop Add / Edit Tags
    Categories
    AOP
  2. More on AOP in Spring Part 1

    by , 11-16-2011 at 05:03 PM
    In the previous tip, we started to look at Aspect Oriented Programming support in Spring. In this tip we will continue with this assessment of this exciting technology. Before we start there are a number of terms that I need to introduce to you in order that you can speak the lingo of AOP. I list these terms below:
    • Advice - I had briefly mentioned this is the last tip. Advice is the code to be executed at a join point that has been selected by a pointcut. Advice can execute before, after,
    ...

    Updated 11-16-2011 at 05:05 PM by Spring Framework

    Categories
    AOP
  3. An Introduction to Aspect Oriented Programming

    by , 11-16-2011 at 04:58 PM
    Aspect-oriented programming (AOP) is a new methodology that provides separation of crosscutting concerns. Crosscutting concerns are system wide concerns that span multiple modules. In applications, these system wide concerns would involve features such as logging, security, persistence and any other element common to a majority of the core business modules. This type of programming is done by introducing a new unit of modularization—an aspect—that crosscuts other modules. Using AOP you would implement ...
    Tags: aop, aspectj Add / Edit Tags
    Categories
    AOP
  4. Advanced Uses of SpEL

    by , 11-16-2011 at 04:50 PM
    There are a number of operations that you can apply on values as well as class scoped methods and constants using SpEL. Consider for example doing basic math operations on values. SpEL supports all the basic arithmetic operations that are supported in Java’s libraries. Consider that if you want to use constants or class-scoped methods you will need to use the T() operator. Below is an example of how it is to be used:

    T(java.lang.Math)

    The creates a Class object that ...
  5. More Simple SpEL Expressions

    by , 11-16-2011 at 04:48 PM
    Another basic thing that a SpEL expression can do is to reference another bean by its ID. With this functionality it is possible to use SpEL to wire one bean into another bean’s property by using the bean ID as the SpEL expression:

    Java Code:
    <property name="engine" value="#{hybrid}"/>
    As you can see, we’re using SpEL to wire the bean whose ID is "hybrid" into an engine property. Now it is possible to do this without SpEL, and you would get ...
  6. The Basics of SpEL

    by , 11-16-2011 at 04:44 PM
    The goal of a SpEL expression is to arrive at some value after evaluation. In the course of calculating that value, other values are considered and operated upon. The simplest kinds of values that SpEL can evaluate may be literal values, references to a bean’s properties, or perhaps a constant on some class.

    The most basic type of SpEL expression is one that contains only a literal value. A literal value would be a perfectly valid SpEL expression:

    Java Code:
    <property name="message"
    ...
  7. Introduction to Spring Expression Language

    by , 11-16-2011 at 04:42 PM
    Up until now, in the tips I’ve shown, all the constructor arguments and bean properties have been statically wired in the Spring configuration XML. What this means is that any definition you make has to be provided during development. This also applies to other beans which need to be defined statically in the Spring configuration.

    In Spring 3, the Spring Expression Language (SpEL) was introduced as a powerful and concise means of dynamically wiring values in constructor arguments ...
  8. Listening for Events in Spring

    by , 11-16-2011 at 04:39 PM
    During the application life cycle, the ApplicationContext will publish a handful of events that tell interested listeners what’s going on. All of these events are all subclasses of the abstract class org.springframework.context.ApplicationEvent. A couple of these subclasses are:
    • ContextClosedEvent—Published when the application context is closed
    • ContextRefreshedEvent—Published when the application context is initialized or refreshed
    • RequestHandledEvent—Published within a web application
    ...

    Updated 11-30-2011 at 04:12 AM by Spring Framework

    Categories
    Application Context , Event
  9. Wiring Bean Post Processor in Spring

    by , 11-16-2011 at 04:32 PM
    In the last post, we create a class AnsiConvertor that implements the BeanPostProcessor interface. Now if we want to use this class in our application is running within a bean factory, we need to programmatically register the BeanPostProcessor using the factory’s addBeanPostProcessor() method:

    Java Code:
    BeanPostProcessor convertAnsi = new ConvertAnsi(); 
    factory.addBeanPostProcessor(convertAnsi);
    Or if you decide to use an application context, you’ll need to register the ...
    Categories
    XML , Bean , Configuration
  10. How to Write a BeanPostProcessing in Spring

    by , 11-16-2011 at 04:28 PM
    In the previous tip we talked about special beans in Spring. One of the Spring’s special beans that I had mentioned was using the BeanPostProcessor interface in order to cut into the bean’s life cycle and review or alter its configuration. In this tip, I will show you how to wire one. As mentioned in the previous tip I mentioned that the BeanPostProcessor provides two methods to alter the bean after it has been created and wired:

    Java Code:
    Object postProcessBeforeInitialization(Object bean,
    ...
  11. Spring's Special Beans

    by , 11-16-2011 at 04:25 PM
    The majority of beans in Spring are configured by the Spring container and made available for use in the application. Apart from these standard beans, Spring also has groups of beans that each serve a special purpose. The way in which Spring identifies these beans is because these beans have implemented certain interfaces that Spring considers special. The use of these interfaces allows these beans to do the following:
    • Post processing bean configuration in order to be involved in the bean
    ...
    Categories
    Bean , Configuration , XML
  12. How to Autowire a Spring Bean

    by , 11-16-2011 at 04:23 PM
    In previous tips, we have shown how to wire bean’s properties using the <property> element. There is an alternative approach that can be used. It’s called autowiring. In this approach, Spring will wire your beans automatically if you set the autowire property on each <bean> on each of the beans that you want to autowire. There are four types of autowiring that Spring uses:

    • byName—Spring will attempt to find a bean in the container whose name (or ID) is the same as the
    ...
  13. Wiring Sets, Maps and Properties in Spring

    by , 11-16-2011 at 04:19 PM
    Similarly to lists, there are times when you will need to map to other types of collections. In this tip, I will outline what you need to do to wire sets, maps and properties. The key to remember is that you want to wire your bean to the same type that is being used in the class definition. So if your bean has a java.util.Set property to guarantee uniqueness in the collection, you want to use the same definition in the xml definition.

    So for example, if you want to use a java.util.Set, ...
  14. Wiring Lists and Arrays in Spring Beans

    by , 11-16-2011 at 04:17 PM
    Often you will have situations where you will need to wire properties that are lists or arrays. If you are using Hibernate jointly with Spring, you will need to se this in order to provide the list of Hibernate mapping files. In order to do this, you will use the <list> element to wire the property in the wiring XML file for either an array property or a java.util.List property.

    For example, when you want to map Hibernate mapping files, you will wire a LocalSessionFactoryBean ...
    Categories
    Bean , Configuration
  15. Spring Inner Beans

    by , 11-16-2011 at 04:15 PM
    Rather than configure beans separately and allow for Spring’s DI container to manage the injection of these beans into other beans, another means of wiring bean references is to embed a <bean> element directly in the <property> element. For example, the carDao property of the carService bean can be wired as follows:

    Java Code:
    <bean id="carService" class="com.acme.springexample.service.CarServiceImpl">
    <property name="carDao">
    ...

    Updated 11-30-2011 at 11:51 AM by Spring Framework

    Categories
    Dependency Injection , Bean
  16. Understanding the Difference Between Singleton vs. Prototyping of Spring Beans

    by , 11-16-2011 at 04:13 PM
    When you configure a new Spring beanBy default, all Spring beans are singletons. When the container dispenses a bean, it will always give the exact same instance of the bean. But sometimes you want the application context to return a unique instance for each time you request a specific bean. In this case, you would want to do is to define a prototype bean. When you define a prototype means that you define a blueprint of the bean. Every subsequent bean for this requested bean will be based on this ...
  17. The Lifecycle of a Spring Bean

    by , 11-16-2011 at 04:11 PM
    In this tip, we will look at the lifecycle of a bean. The bean lifecycle for a Spring bean is somewhat complex. It is important to understand the life cycle of a Spring bean. Otherwise it will be difficult for you as a programmer to use Spring to its full abilities especially because you may want to take advantage of some of the opportunities that Spring offers to customize how a bean is created. The startup life cycle of a typical bean as it is loaded into a BeanFactory container is shown: ...
    Categories
    Bean
  18. Using View Helper in Spring MVC

    by , 11-16-2011 at 04:08 PM
    When you are looking to create the web front-end to your application, anyone with exposure to design patterns would apply the MVC pattern for this aspect of the application. There are a number of ways to do this, in Spring Framework, the means of accomplishing this is via an application controller and page controllers combined with a gateway servlet. This design resolves three important concerns of request processing:
    1. Request interception
    2. Invoking business components from page controllers
    3. Resolving
    ...
    Categories
    View Helper , MVC
  19. Listening for Events with Spring

    by , 11-16-2011 at 04:03 PM
    During the application life cycle, the ApplicationContext will publish a handful of events that tell interested listeners what’s going on. All of these events are all subclasses of the abstract class org.springframework.context.ApplicationEvent. A couple of these subclasses are:
    • ContextClosedEvent—Published when the application context is closed
    • ContextRefreshedEvent—Published when the application context is initialized or refreshed
    • RequestHandledEvent—Published within a web application
    ...
    Categories
    Event
  20. Working with Spring's Bean Factories

    by , 11-16-2011 at 12:18 PM
    BeanFactory serves as the core to Spring's Dependency Injection implementation. A BeanFactory is responsible for managing components and their dependencies. Bean is the term used in Spring to refer to any component managed by the container. Typically all Spring beans adhere, at some level, to the JavaBeans specification, although it is not required. The most obvious case of Spring deviating from the JavaBean specification is with the use of Constructor Injection to wire your beans together. ...
  21. Contextualized Dependency Lookup in Spring

    by , 11-16-2011 at 12:16 PM
    At its core, Inversion of Control (IoC), and therefore Dependency Injection (DI) offers a mechanism for provisioning component dependencies and managing these dependencies throughout their lifecycles. A component that requires certain dependencies is often referred to as the dependent object or, in the case of IoC, the target. Generally, IoC can be broken down into two subtypes: Dependency Injection and Dependency Lookup. With Dependency Lookup IoC, a component must obtain a reference to a dependency. ...
  22. Struts Action Class

    by , 11-15-2011 at 06:39 PM (My Java Tips)
    In this article let us see how to use Struts Action Class and forward a jsp file through it.



    Introduction

    An Action class in the struts application extends Struts 'org.apache.struts.action.Action" Class. Action class acts as wrapper around the business logic and provides an interface to the application's Model layer. It acts as glue between the View and Model layer. It also transfers the data from the view layer to the specific business process layer and ...
  23. Sending files from Servlet

    by , 11-15-2011 at 06:35 PM (My Java Tips)
    In this post, I will present an example which will show how to move the selected file (drop down menu) form a servlet to another servlet which performs operations on the file.


    I have created 3 Javafiles namely:

    - HelloServlet(Servlet)
    - GetImg (Servlet)
    - ImgCompare (simpleJava class)

    HelloServlet contains a HTML form that has a dropdown menu. Menu contains 2 JPG files. You should have following images at the given path:

    C:\image1.jpg ...
    Categories
    Java EE
  24. Java Generics with legacy code

    by , 11-15-2011 at 06:31 PM (My Java Tips)
    In this post, I will write about how Java generics help us in using legacy code.


    Generics are new in Java and now developers understand the importance of it and it is being used as required. Question arises, what about the legacy code? Consider an IT firm that is working on an application for 5 years, and they used Java 1.4 for development. They the plan to use 1.5 for development simply because it is better than 1.4. Are they supposed to convert the old code to 1.5 also? This is ...
  25. Using tags in Struts

    by , 11-15-2011 at 06:26 PM (My Java Tips)
    Web applications differ from conventional websites in that web applications can create a dynamic response. To make it easier to reference dynamic data from a page, the Struts framework offers a set of tags. Some of the tags mimic standard HTML tag while providing added value. Other tags create non-standard, but useful controls. While HTML provides a simple a tag for creating hyperlinks, the HTML tag often requires us to include redundant information. Also the HTML tag cannot easily access dynamic ...
    Categories
    Struts
  26. Struts”Hello World”

    by , 11-15-2011 at 06:15 PM (My Java Tips)
    Lets make a HelloWorld example using Struts.


    Suppose you want to create a simple "Hello World" example that displays a welcome message. To create a "Hello World" example, you need to do three things:

    1. Create a server page HelloWorld.jsp to present the messages

    Java Code:
    &lt;%@ taglib prefix="s" uri="/struts-tags" %&gt;
    <h2><s:property value="message"></s:property></h2>
    ...

    Updated 11-15-2011 at 06:21 PM by Java Tip

    Categories
    Struts
  27. Setup a Struts 2 application

    by , 11-15-2011 at 06:08 PM (My Java Tips)
    in this post, I will write about how to setup a Struts 2 application from scratch. This will be interesting for the developer who are using Struts for the very first time.


    Download the latest struts framework from the http://struts.apache.org. To get started with a new application you can setup a web infrastructure from scratch.

    Setup the Web Application File Structure as follows within webapps folder. (This tutorial assumes that you are using Apache Tomcat as a web ...
  28. Apache Struts

    by , 11-15-2011 at 06:03 PM (My Java Tips)
    Apache Struts is a free open-source framework for creating Java web applications. In this post, I will write about Apache Struts.


    In a standard Java EE web application, the client will typically submit information to the server via a web form. The information is then either handed over to a Java Servlet which processes it, interacts with a database and produces an HTML-formatted response, or it is given to a JavaServer Pages (JSP) document which intermingles HTML and Java code to ...
  29. Looking at Spring's Bean Factories

    by , 11-15-2011 at 02:17 PM
    BeanFactory serves as the core to Spring's Dependency Injection implementation. A BeanFactory is responsible for managing components and their dependencies. Bean is the term used in Spring to refer to any component managed by the container. Typically all Spring beans adhere, at some level, to the JavaBeans specification, although it is not required. The most obvious case of Spring deviating from the JavaBean specification is with the use of Constructor Injection to wire your beans together. ...
    Categories
    Uncategorized
  30. Looking at the Spring Application Context

    by , 11-15-2011 at 02:13 PM
    In order to take advantage of the full power of the Spring framework, you need to use Spring’s most advanced container, the application context. The ApplicationContext is similar to a BeanFactory. Both load bean definitions, wire beans together, and dispense beans upon request. But an ApplicationContext also does the following:
    • Application contexts provide a generic way to load other resources, such as images.
    • Application contexts can publish events to beans that are registered as listeners.
    • Application
    ...

    Updated 11-30-2011 at 11:46 AM by Spring Framework

    Categories
    Application Context
Page 36 of 48 FirstFirst ... 26343536373846 ... LastLast