View RSS Feed

All Blog Entries

  1. Viewing Options in Spring

    by , 11-30-2011 at 05:38 AM
    In your application, once the service have handled the request and returned the results desired, you will need to render the results in a useful manner to the user. This is the purpose of viewing technology such as JavaServer Pages (JSP). Although you can use JSPs in Spring there are a number of other viewing technologies that Spring support. In this tip, I will outline some of the other view technologies that are available.

    When Spring is looking to render some content, the DispatcherServlet ...
  2. Introduction to Spring Web Flow

    by , 11-29-2011 at 03:49 AM
    When you are developing an user interaction for an application, one of the most challenging aspects is to define a proper narrative for the behavior of the application so that the user can get into a flow while using the application. Sometimes it is necessary to step a user through a process, such as ordering a plane ticket. This is called a flowed application. Now is a possible to use any web framework, such as Struts or Java Server Faces, in order to do this. Unfortunately none of them properly ...
  3. Data Access with Java Persistence API

    by , 11-29-2011 at 03:44 AM
    Spring integration with Java Persistence API (JPA) came about on the release of Spring 2.0. It is very easy to use JPA with Spring because it is all based on plain old java beans (POJOs). In this tip, we will outline the steps required for you to use JPA with Spring.

    JPA-based applications are based on the implementation of EntityManagerFactory in order to get an instance of an EntityManager. There are two kinds of entity managers from the JPA Specification that both implement the ...

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

    Categories
    JPA , Spring 3 , EntityManager , EntityManagerFactory
  4. Resource Representation in Spring

    by , 11-28-2011 at 02:05 AM
    In my previous tips, I looked out how to make the key RESTful method calls. In all of them the controller’s handler method finishes, and a logical view name is usually returned. In the case that the method doesn’t return a logical view name (a method returning void) then the logical view name is derived from the request’s URL. The DispatcherServlet passes the view name to a view resolver in order to facilitate the determination of which view should render the results of the request.

    ...

    Updated 11-30-2011 at 02:42 PM by Spring Framework

    Categories
    Configuration , View , XML , REST , Resource
  5. RESTful POST Method in Spring

    by , 11-28-2011 at 02:02 AM
    In my previous tips, I have shown you how to write RESTful methods for GET, PUT and DELETE. In this tip, I will tackle the method which is probably the most used (and abused), the POST method.

    The POST method is the one method that you need to be most mindful of. First it is not safe and second it is not idempotent. Therefore you must take extra care in how you design your URL as well as your method . In this case, I will add another method to the CarController that creates a new ...

    Updated 11-30-2011 at 02:41 PM by Spring Framework

    Categories
    HTTP , REST
  6. RESTful DELETE Method in Spring

    by , 11-28-2011 at 01:59 AM
    Continuing on my previous tip, of showing how to write RESTful methods, in this tip, I will show you how to write RESTful methods using the verb HTTP Verb, PUT.

    There are times when we might want to get rid of a resource in its entirety. In the case we would use the HTTP DELETE method in order to accomplish this. In this case, I will add another method to the CarController that handles the DELETE requests to remove a Car resource:

    Java Code:
    @RequestMapping(value="/{id}",
    ...

    Updated 11-30-2011 at 02:40 PM by Spring Framework

    Categories
    REST , HTTP
  7. RESTful PUT Method in Spring

    by , 11-28-2011 at 01:56 AM
    In my previous tip, I looked at the verbs available for RESTful services. In this tip, I will show you how to write RESTful methods using the verb HTTP Verb, PUT.

    The purpose of the PUT method’s is exactly as it states. Is serves to transfer the resource’s state from the client to the server. For an example of this, please see the following method that I’ve created for putCar() that is annotated to receive a Car object from a PUT request:

    Java Code:
    @RequestMapping(value="/{id}",
    ...

    Updated 11-30-2011 at 02:39 PM by Spring Framework

    Categories
    REST , HTTP
  8. Key REST Verbs

    by , 11-28-2011 at 01:54 AM
    In my previous tip, I looked at setting up RESTful Controllers. Now in the post we will look at the verbs available for RESTful services. . Although this is nice for writing RESTless controllers, it is not ideal for writing RESTful controllers. The reason is that controllers made in this way are action oriented and not resource oriented. This can be easily surmised by the names used for the different requests which are focused on the particular use cases but not on the resources.

    ...

    Updated 11-30-2011 at 02:39 PM by Spring Framework

    Tags: rest, spring, verbs Add / Edit Tags
    Categories
    REST , HTTP
  9. RESTful Controllers in Spring

    by , 11-28-2011 at 01:47 AM
    In my previous tip, I presented to you an overview of how to handle RESTful URLs. In this tip, I will followup will look at RESTful Controllers. From my previous posts, I believe you have surmised that Spring MVC’s model is a very flexible framework for for writing controller classes. Almost any method with almost any signature can be annotated to handle a web request. Although this is nice for writing RESTless controllers, it is not ideal for writing RESTful controllers. The reason is that controllers ...
    Categories
    Controller , REST , Spring 3 , MVC
  10. RESTful URLs in Spring

    by , 11-28-2011 at 01:31 AM
    In my previous tip, I presented to you an overview of Spring support of REST. In this tip, I will followup with a tip for look at RESTful URLs.

    If you want to create a RESTful controller, you will need to handle URLs in a RESTful way. That’s because everything that’s done in REST is done through a URL. The URL’s RESTful nature is even implied by it’s name, uniform resource locator. Given that name, it seems that a URL is intended to locate a resource. Above and beyond this, URLs ...

    Updated 11-30-2011 at 02:37 PM by Spring Framework

    Categories
    Web , Web Service , REST
  11. REST Services in Spring

    by , 11-28-2011 at 01:28 AM
    In Spring 3.0, the Spring team added support for Representational State Transfer (REST). It has emerged as a popular information-centric alternative to traditional SOAP-based web services. Spring developers have taken advantage of the REST architectural model to pack the Spring MVC with first-class support for working with REST. In this tip, we will look at the fundamentals of REST.

    In order to understand what REST is all about, it helps to break down the acronym into its constituent ...
    Categories
    Web Service , REST , Spring 3
  12. Proxying JAX-WS Services in Spring

    by , 11-28-2011 at 01:25 AM
    I have been exploring JAX-WS services in Spring. In this tip, I will look into proxying JAX-WS services on the client side. Consuming web services with Spring involves client-side proxies in a way similar to how Spring based clients consume other remoting technologies.

    Using JaxWsPortProxyFactoryBean is used to wire the Car web service in Spring similar to any other Spring bean. The JaxWsPortProxyFactoryBean is a factory bean that produces a proxy that knows how to talk to a SOAP ...

    Updated 11-30-2011 at 02:36 PM by Spring Framework

    Categories
    Web , Web Service
  13. How to Export JAX-WS EndPoints in Spring

    by , 11-28-2011 at 01:22 AM
    In my previous tip, I showed you how to autowire a JAX-WS endpoint. Although this is very useful, but recognize that the objects whose properties are being injected doesn’t have its lifecycle managed by Spring. There are circumstances though, where it’s possible to export a Spring-managed bean as a JAX-WS endpoint. In this tip, I will show you how.

    Spring’s SimpleJaxWsServiceExporter works by publishing Spring-managed beans as service endpoints in a JAX-WS runtime. SimpleJaxWsServiceExporter ...

    Updated 11-30-2011 at 02:35 PM by Spring Framework

    Categories
    Web Service , Spring 3 , Web
  14. Intro to Web Services with Spring

    by , 11-28-2011 at 12:02 AM
    One of the most important changes in IT in the last 10 years has been the advent of Service Oriented Architecture (SOA). At the core SOA is the idea of building system via a common set of core services rather than the traditional monolithic method. Java and web services have been intimately intwined. There are a number of options are available for working with web services in Java. Spring facilitates the integration of many of these options. In fact, Spring provides support for publishing and consuming ...

    Updated 11-30-2011 at 02:35 PM by Spring Framework

    Categories
    Web , Web Service , Spring 3
  15. Login Forms with Spring Security

    by , 11-27-2011 at 11:51 PM
    In my previous tips I showed how to add in the necessary servlet filters in your Spring application file and then to configure minimal security in your Spring application. In this tip, we will look at setting up a form for logging into an application.

    As I mention in the last tip, by setting auto-config to true, the autoconfiguration give our a free login page, support for HTTP Basic authentication and logging out, and Spring Security will automatically generate a login page page. ...
    Categories
    Security , Web , Spring 3
  16. Using Annotations for Transactions in Spring

    by , 11-27-2011 at 11:38 PM
    In the previous tip, I showed you how you could use XML to define a transaction. In this tip we will look at doing the same using annotations. It is blindly simple to use annotations for transactions. The tx namespace provides the <tx:annotation-driven> element. It appears like this :

    Java Code:
    <tx:annotation-driven transaction-manager="txManager" />
    With this you can now define transaction rules very easily. This tag tells Spring to examine all beans in ...
  17. Configuring Transactions in XML with Spring

    by , 11-27-2011 at 11:33 PM
    Continuing from my previous post, I will demonstrate how you can declare transactions in XML using Spring. Continuing from the previous tips on transaction attributes, let’s dive straight in. Spring has a tx configuration namespace to simply declaring transactions in Spring. It is recommended that you include the aop namespace as well since some of the declarative transaction configuration elements use AOP configuration elements. The following shows how <tx:advice> is used for the Car service. ...

    Updated 11-27-2011 at 11:36 PM by Spring Framework

    Categories
    Spring 3 , Configuration , Transaction , XML
    Attached Thumbnails Attached Images  
  18. Transaction Propagation Strategies in Spring

    by , 11-27-2011 at 11:29 PM
    In the previous tip, we looked at the key properties that are required for handling any transaction. In Spring, when you want to have your application are using. Spring transaction concepts are taken from the JEE specification specifically the EJB 3.0 specification. Another key aspect of managing transactions is the ability to control the propagation of transactions in your application. Spring has the org.springframework.transaction.TransactionStatus interface that allows an application to check ...
  19. Key Attributes of Spring Transactions

    by , 11-27-2011 at 11:25 PM
    Transactions are defined as doing a business unit of work. It is a key functionality that enable you to control concurrent access of data by multiple business operations. This is done in order to safeguard integrity and ensure that data remains in a consistent state. If for any reason the unit of work could not be completed as an indivisible unit of work, all the changes are unwound and the system is returned to its previous state. The key properties for the design of any application is to ensure ...

    Updated 11-30-2011 at 02:06 PM by Spring Framework

    Categories
    Transaction
  20. Serving Static Content in Spring

    by , 11-27-2011 at 11:06 PM
    If you are concern you that DispatcherServlet will be handling static content requests, Spring has features that can help you to deal with this. Spring’s mvc namespace includes a <mvc:resources> element that handles requests for static content for you. In the following example, I show you how you can create an xml file that the DispatcherServlet can use to create an application context.

    Java Code:
    <?xml version="1.0" encoding="UTF-8"?> 
    <beans xmlns="http://www.springframework.org/schema/beans"
    ...

    Updated 11-30-2011 at 01:59 PM by Spring Framework

    Categories
    MVC
  21. Configuring a Spring Data Source Continued

    by , 11-27-2011 at 11:02 PM
    There are a number of DataSource connection pool implementations provided by different vendors as well as projects like C3PO and Apache Commons DBCP providing popular open-source options. It is easy to switch between different data source implementations, because of the common DataSource interface. Spring provides a convenient data source implementations as well but it is not considered as powerful as the vendor or open source implementations. The simplest one is org.springframework.jdbc.datasource.DriverManagerD ataSource, ...
  22. Writing A Namespace Handler in Spring

    by , 11-27-2011 at 10:58 PM
    Custom XML namespaces were introduced in Spring 2.0. Similar to Java packages, custom namespaces make it possible to define components without concern of colliding with other named components. Spring has already some predefined namespaces such as jee, aop, util, as well as others. Custom namespaces are handled using the NamespaceHandlerSupport class that generates metadata to be consumed by the Spring framework. This metadata is processed by parser classes that are also supplied by a component developer. ...
  23. Introducing Behaviors to Your Spring Beans

    by , 11-27-2011 at 10:55 PM
    In Spring AOP, you can use what is called an introduction (a special type of advice) that enables your objects to implement an interface dynamically, by providing the implementation class for that interface. This behavior can be multiplied to give the impression of multiple inheritance to your beans. To define an introduction, use the @DeclareParents annotation, which gives matching types a new parent.

    Java Code:
    package com.acme.springexamples.derivautos;
    import org.aspectj.lang.annotation.Aspect;
    ...
    Categories
    Bean , Spring 3
  24. Configuring Data Sources in Spring

    by , 11-27-2011 at 10:51 PM
    Spring offers a number of options for configuring a data sources via data source beans. These sources include the following:
    • Data sources that use JNDI
    • Data sources that use JDBC drivers
    • Data sources that pool connections


    There is significant differences in the features available depending on what you are trying to do. In this tip, I will outline how to configure different data sources and what they are best used for.

    If you are looking to do really robust ...
  25. Internationalization with Spring

    by , 11-27-2011 at 10:43 PM
    Often it is necessary for an application to be able to support several languages in order to address the requirements of customers located in different countries. For this java has support for what is called internationalization (i18n) that allows allows for an application to resolve text messages for different locales. The means of doing this in Java is to use what is called a ResourceBundle. These are property files that contain a key/message pair and have a special naming convention for the file ...
  26. Using Spring Data Access Support with Hibernate

    by , 11-27-2011 at 10:35 PM
    In our previous tip, I gave an introduction to Spring’s persistence technology agnostic approach to data access. In this tip, we will show you how to use Spring with one of the most popular persistence technologies, Hibernate. Hibernate is an open source persistence framework that is one of the most successful persistence frameworks in the developer community. The reason for this is that it is a full featured object relational mapping (ORM) tool. It provides all the features you’d expect from a ...
  27. Database Support in Spring

    by , 11-16-2011 at 06:40 PM
    In our next tip, I will focus on Spring’s data access support. Spring uses the design pattern, data access object (DAO). The purpose of DAOs is to provide means to read and write data to the database. So what Spring has focused on is to make it easy for developers to write DAOs as irrespective of whether you use JDBC, Hibernate, JPA or JDO. The way in which it does this is by separating the interface from the data access implementation. Therefore the implementation can change to align with the ...
    Categories
    Hibernate , JDBC , JPA
  28. Introduction to Spring Expression Language

    by , 11-16-2011 at 05: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 ...
  29. Listening for Events in Spring

    by , 11-16-2011 at 05: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 05:12 AM by Spring Framework

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

    by , 11-16-2011 at 05: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
    Bean , Configuration , XML
Page 1 of 2 12 LastLast