Showing posts with label spring framework. Show all posts
Showing posts with label spring framework. Show all posts

Monday, February 4, 2013

A Spring summary: The Spring framework is still relevant



This article by Ken Rimple is from a post on Serverside.com
A Spring summary: The Spring framework is still relevant 
With the advent of the simpler versions of Java EE comes a chorus of Java EE aficionados calling for developers to jettison proprietary application frameworks and embrace the core. Spring is one framework targeted for elimination, and several articles and tutorials have claimed that it's obsolete.
To kick off a regular monthly column on TSS, I'll tackle the question of why the Spring framework is still popular today. I'll discuss the platform's strengths, innovations, the power of the Spring container, contrasts and comparisons with Java EE, and some areas where SpringSource, a division of VMware, is totally ahead of the game.
Before I begin, let me lay my bias on the table. I've been working with Spring since 2006, when I ran into it on a project at my prior employer. I had been working with Java EE since the original 1.0 version and Java since 1.0.2. When I saw how the Spring framework simplified my life, I looked for a chance to work with it more. Having a background as a mentor, trainer and leader, I approached Chariot Solutions about teaching Spring in 2007, and I've been here ever since.
Chariot is a SpringSource/VMware training and solutions partner. I lead our training team, but these opinions are my own. Chariot also partners with a number of other technology firms in the enterprise application integration and development space.

Why is Spring so popular?

Simply put, Spring is so popular today because it simplifies development drastically for Java EE developers. Rod Johnson created Spring when he was writing a book on J2EE application design and felt the frustrations that most of us had with the specification. One chief concern was the emphasis on architecting separate Enterprise JavaBeans and processing them to generate deployment JARs. Another was the API's focus on framework interfaces -- home, local and remote interfaces -- not to mention that back in 2001, it took an expensive, heavyweight platform such as WebSphere or WebLogic to deploy these applications.

Tuesday, January 24, 2012

Spring 3.1 - Constructor Namespace

Spring Namespaces


Spring provides several namespaces to simplify XML configuration, such as jdbc, tx, aop, etc. We Spring developers are already familiar with the required beans namespace.

<beans>
  <bean id="dataSource" class="..."/>
  <bean id="messagingProvider" class="..."/>
</beans>

Spring Namespaces are defined at the top of the XML file. Here we define the namespaces we need to use, and reference the schema (XSD) that validates the XML.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="com.chariotsolutions"/>

    <bean id="simpleBean"
      class="com.chariotsolutions.springthreeone.SimpleBean"/>

</beans>

In Spring XML configuration we declare dependency injection with either "setter injection" (via properties tag) or "constructor injection". Spring already provided the Property or "p" namespace, to simplify property setting, in other words, invoking setters on a bean.

Here we have a simple bean that can be configured with either a constructor or setter.

public class SimpleBean {
  private String myString;
  private String myOtherString;

  public SimpleBean() {}

  public SimpleBean(String myString) {
    this.myString = myString;
  }

  public SimpleBean(String myString, String other) {
    this.myString = myString;
    this.myOtherString = other;
  }

  public String getMyString() {
    return myString;
  }

  public String getMyOtherString() {
    return myOtherString;
  }
}


Instead of

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="setterBean"
      class="com.chariotsolutions.springthreeone.SimpleBean">
        <property name="myString" value="Setter Set"/>
    </bean>

</beans>

We could use

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:p="http://www.springframework.org/schema/p"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd">

  <bean id="setterBean"
    class="com.chariotsolutions.springthreeone.SimpleBean"
      p:myString="Setter Set"/>

</beans>

With the Property namespace, there is no significant benefit, it is simple a matter of preference.


Spring Constructor Injection

Some developers choose to use "constructor injection" for several reasons.
  • Setting required elements
  • Immutable classes for thread safety
  • Third party class that only provides constructor setting

One of the main issues with "constructor injection", prior to Spring 3.1, is that it is unclear which arguments are being set in the constructor injection. Also, if the constructor has multiple arguments, one can inadvertently set arguments in the wrong sequence.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd">

  <bean id="setterBean" class="com.chariotsolutions.springthreeone.SimpleBean">
    <constructor-arg value="squibbity doo"/>
    <constructor-arg value="flabbity doo"/>
  </bean>
</beans>

Spring 3.1 Constructor "c" Namespace

Unlike the "p" namespace, the "c" namespace provides us with descriptive references, allowing us to reference the constructor's arguments by name. This feature is even more useful when we have multiple constructor arguments, as below.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:c="http://www.springframework.org/schema/c"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd">

  <bean id="setterBean" class="com.chariotsolutions.springthreeone.SimpleBean"
    c:myString="squibbity doo"
    c:myOtherString="flabbity doo"/>

</beans>

Deployment Requirements

NOTE: Code using the "c" namespace, MUST be deployed with Java Debugging Tables (the -g option)!


Summary

We Spring developers have shortcuts at our disposal to make configuration easier or less terse. The new "c" namespace provides us the benefit of named variables that we know from using the "p" namespace or <property ... />. We should strive to make our beans immutable for thread safety. By using the "c" namespace get the developers lean towards property setting for readability.

Notice that both the "p" ad "c" namespaces do not have a schema reference in the XML header.

Tuesday, January 17, 2012

Spring 3.1 - Environment Profiles

Spring 3.1 Environment Profiles

Profiles

Spring 3.1 now includes support for the long awaited environment aware feature called profiles. Now we can activate profiles in our application, which allows us to define beans by deployment regions, such as "dev", "qa", "production", "cloud", etc.

We also can use this feature for other purposes: defining profiles for performance testing scenarios such as "cached" or "lazyload".

Essential Tokens

Spring profiles are enabled using the case insensitive tokens spring.profiles.active or spring_profiles_active.

This token can be set as:
  • an Environment Variable
  • a JVM Property
  • Web Parameter
  • Programmatic
Spring also looks for the token, spring.profiles.default, which can be used to set the default profile(s) if none are specified with spring.profiles.active.

Grouping Beans by Profile

Spring 3.1 provides nested bean definitions, providing the ability to define beans for various environments:
<beans profiles="dev,qa">
  <bean id="dataSource" class="..."/>
  <bean id="messagingProvider" class="..."/>
</beans>
Nested <beans> must appear last in the file.
Beans that are used in all profiles are declared in the outer <beans> as we always have, such as Service classes.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:c="http://www.springframework.org/schema/c"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="businessService"
       class="com.c...s.springthreeone.business.SimpleBusinessServiceImpl"/>

    <beans profile="dev,qa">
        <bean id="constructorBean"
          class="com.chariotsolutions.springthreeone.SimpleBean"
              c:myString="Constructor Set"/>

        <bean id="setterBean"
          class="com.chariotsolutions.springthreeone.SimpleBean">
            <property name="myString" value="Setter Set"/>
        </bean>
    </beans>

    <beans profile="prod">
        <bean id="setterBean"
          class="com.chariotsolutions.springthreeone.SimpleBean">
            <property name="myString" value="Setter Set - in Production YO!"/>
        </bean>
    </beans>
</beans>

If we put a single <bean> declaration at below any nested <beans> tags we will get the exception org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'bean'.

Multiple beans can now share the same XML "id"
In a typical scenario, we would want the DataSource bean to be called dataSource in both all profiles. Spring now allow us to create multiple beans within an XML file with the same ID providing they are defined in different <beans> sets. In other words, ID uniqueness is only enforced within each <beans> set.

Automatic Profile Discovery (Programmatic)

We can configure a class to set our profile(s) during application startup by implementing the appropriate interface. For example, we may configure an application to set different profiles based on where the application is deployed - in CloudFoundry or running as a local web application. In the web.xml file we can include an Servlet context parameter, contextInitializerClasses, to bootstrap this class:
<context-param>
  <param-name>contextInitializerClasses</param-name>
  <param-value>com.chariotsolutions.springthreeone.services.CloudApplicationContextInitializer</param-value>
</context-param>

The Initializer class
package com.chariotsolutions.springthreeone.services;

import org.cloudfoundry.runtime.env.CloudEnvironment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;

public class CloudApplicationContextInitializer implements
  ApplicationContextInitializer<ConfigurableApplicationContext> {
    
  private static final Logger logger = LoggerFactory
    .getLogger(CloudApplicationContextInitializer.class);

  @Override
  public void initialize(ConfigurableApplicationContext applicationContext) {
    CloudEnvironment env = new CloudEnvironment();
    if (env.getInstanceInfo() != null) {
      logger.info("Application running in cloud. API '{}'",
        env.getCloudApiUri());
      applicationContext.getEnvironment().setActiveProfiles("cloud");
      applicationContext.refresh();
    } else {
      logger.info("Application running local");
      applicationContext.getEnvironment().setActiveProfiles("dev");
    }
  }
}

Annotation Support for JavaConfig

If we are are using JavaConfig to define our beans, Spring 3.1 includes the @Profile annotation for enabling bean config files by profile(s).

package com.chariotsolutions.springthreeone.configuration;

import com.chariotsolutions.springthreeone.SimpleBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
@Profile("dev")
public class AppConfig {
  @Bean
  public SimpleBean simpleBean() {
    SimpleBean simpleBean = new SimpleBean();
    simpleBean.setMyString("Ripped Pants");
    return simpleBean;
  }
}

Testing with XML Configuration

With XML configuration we can simply add the annotation @ActiveProfiles to the JUnit test class. To include multiple profiles, use the format @ActiveProfiles(profiles = {"dev", "prod"})
package com.chariotsolutions.springthreeone;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@ActiveProfiles(profiles = "dev")
public class DevBeansTest {

  @Autowired
  ApplicationContext applicationContext;

  @Test
  public void testDevBeans() {
    SimpleBean simpleBean = 
      applicationContext.getBean("constructorBean", SimpleBean.class);
    assertNotNull(simpleBean);
  }

  @Test(expected = NoSuchBeanDefinitionException.class)
  public void testProdBean() {
    SimpleBean prodBean = applicationContext.getBean("prodBean", SimpleBean.class);
    assertNull(prodBean);
  }
}

Testing with JavaConfig

JavaConfig allows us to configure Spring with or without XML configuration. If we want to test beans that are defined in a Configuration class we configure our test with the loader and classes arguments of the @ContextConfiguration annotation.

package com.chariotsolutions.springthreeone.configuration;

import com.chariotsolutions.springthreeone.SimpleBean;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;

import static org.junit.Assert.assertNotNull;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = AppConfig.class, loader = AnnotationConfigContextLoader.class)
@ActiveProfiles(profiles = "dev")
public class BeanConfigTest {

  @Autowired
  SimpleBean simpleBean;

  @Test
  public void testBeanAvailablity() {
    assertNotNull(simpleBean);
  }
}

Declarative Configuration in WEB.XML

If we desire to set the configuration in WEB.XML, this can be done with parameters on ContextLoaderListener.

Application Context
<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/app-config.xml</param-value>
</context-param>
<context-param>
  <param-name>spring.profiles.active</param-name>
  <param-value>DOUBLEUPMINT</param-value>
</context-param>
Log Results

DEBUG PropertySourcesPropertyResolver - Found key 'spring.profiles.active' in [servletContextInitParams] with type [String] and value 'DOUBLEUPMINT'


Environment Variable/JVM Parameter
Setting an environment variable can be done with either spring_profiles_default or spring_profiles_active. In Unix/Mac it would be export SPRING_PROFILES_DEFAULT=DEVELOPMENT for my local system.

We can also use the JVM "-D" parameter which also works with Maven when using Tomcat or Jetty plugins.

Note: Remember the tokens are NOT case sensitive and can use periods or underscores as separators. For Unix systems, you need to use the underscore, as above.

Logging of system level properties DEBUG PropertySourcesPropertyResolver - Found key 'spring.profiles.default' in [systemProperties] with type [String] and value 'dev,default'

Summary

Now we are equipped to activate various Spring bean sets, based on profiles we define. We can use  traditional, XML based configuration, or the features added to support JavaConfig originally introduced in Spring 3.0.

Monday, July 25, 2011

Roo In Action Corner - Testing Entity Validations With A Mock Entity

This article references the Manning book Spring Roo in Action, which Ken Rimple is currently authoring.  It is available as a Manning MEAP.

I've been working hard on the more advanced chapters of Roo in Action, and as part of this I've amassed some background material that didn't make it into the book.  This topic, using Spring's Mock Entity support, was one of those topics that didn't get a lot of attention.
In Spring Roo in Action, Chapter 3, I discuss how Roo automatically executes the Bean Validators when persisting a live entity. However, when running unit tests, we don't have a live entity at all, nor do we have a Spring container - so how can we exercise the validation without actually hitting our Roo application and the database?

Monday, May 16, 2011

Spock It Like You Mean It!

This post was just put up on the blog of one of our architects, Anatoly Polinsky.  Anatoly has a playful take on Spock, a Groovy testing framework, and specifically, abotu connecting Spock with Spring and DbUnit.


So here we go.. Yesterday night we hacked our way into The Ancient Database where besides the data about ancients themselves, we found incredible stats about many different living species of all the planets ancients traveled to.
So what do we do now? Well, we need a way to query/read this data. So we asked Sam to develop a reader ( ancients called it a ‘DAO’ ) to find a number of living species on each planet since the “beginning of time”.
So she did, and called this “species reader” a ‘SpeciesDao’.
We, of course, trust Sam. But in ancient technology, trust is always based on challenging the assumption by testing all the possible permutations. So we are calling Mr. Spock to help us out…
Sam of course used a well known ancient technique ( code name: Spring Framework ) to create a “species reader”, so Mr. Spock will use all the goodies of this technique to inject all the dependencies ( e.g. data source, a reader itself, etc.. ) for a test.

Read more...



Monday, March 21, 2011

What is in my Spring Context?

When we are learning Spring, there are times we are not sure which beans are in the Spring context. Especially when we use convenient features of Spring 3 such as <context:annotation-driven/> or <context:component-scan/>. As developers, we want to inspect the classes that are automatically registered providing the opportunity to look at the source code and javadocs to see what each class does.


JUnit Tests get Application Context

Our JUnit tests have the ability to inject the Application Context. This is one of the many benefits of @RunWith(SpringJUnit4ClassRunner.class)


@ContextConfiguration(value = "/META-INF/spring/test-app-context.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class BeansInContextTest {

@Autowired
ApplicationContext applicationContext;



Simple Code

Let's loop through all the beans that are defined or discovered with the following code.


@Before
public void setup() {
logger.debug("********************");
String[] beans = applicationContext.getBeanDefinitionNames();
for (String o : beans) {
logger.debug("________________________");
logger.debug("BEAN = " + o);
logger.debug("\tType = " + applicationContext.getType(o));
String[] aliases = applicationContext.getAliases(o);
if (aliases != null && aliases.length > 0) {
for (String a : aliases) {
logger.debug("\tAliased as: " + a);
}
}
}

logger.debug("********************");
logger.debug("*** Number of Beans = {} ***",
applicationContext.getBeanDefinitionCount());
logger.debug("********************");
}
}




What is the Alias?

We can define beans with "id" which by XML law requires it to be unique per file. This restricts us in the ability to use special symbols for the name should we want to. I recommend using "id" unless absolutely necessary. However, should we what to refer to the bean with multiple names or use special symbols, we can use the "name" attribute. By comma separating the tokens, we have the opportunity to refer to a bean with any of the tokens provided.
<bean name="mailServer/default, mailServer" class="..."/>
If no, "id" is provided, the first token becomes the primary and the subse quent tokens become aliases. Does this matter in the usage of the beans? No. But to find "all" the names of the beans, we would display the aliases in addition to the bean names.

The Full Test Code

package com.chariot.sample;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@ContextConfiguration(value = "/META-INF/spring/test-app-context.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class BeansInContextTest {
private final Logger logger = LoggerFactory
.getLogger(BeansInContextTest.class);

@Autowired
ApplicationContext applicationContext;

@Before
public void setup() {
logger.debug("********************");
String[] beans = applicationContext.getBeanDefinitionNames();
for (String o : beans) {
logger.debug("________________________");
logger.debug("BEAN = " + o);
logger.debug("\tType = " + applicationContext.getType(o));
String[] aliases = applicationContext.getAliases(o);
if (aliases != null && aliases.length > 0) {
for (String a : aliases) {
logger.debug("\tAliased as: " + a);
}
}
}

logger.debug("********************");
logger.debug("*** Number of Beans = {} ***",
applicationContext.getBeanDefinitionCount());
logger.debug("********************");
}
}


Sample Bean Context


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<context:annotation-config/>

<bean id="myBean" class="MyCoolBean"/>

</beans>


Experiment and Have Fun

Add beans to the config file. Import other config files and see what happens.

Wanna Learn More?

Learn more about what goes on Spring Context by attending a Core Spring Training class at Chariot.





Thursday, February 17, 2011

JUnit & Spring – What You Don’t Know

 Gordon Dickens, Chariot architect and one of our education trainers, recently wrote this blog post on JUnit and Spring.


When using JUnit in Spring there are several features added that many developers are not aware of.
First, if you are including the Spring Context in your tests, it becomes an Integration Test, no longer a Unit Test.

1. Default Searching of Context File(s)

To instruct Spring to load beans for the tests in the class, we annotate the class with @ContextConfiguration

1a. No File Specified

@ContextConfiguration – with no parameters, (by Default) looks for the config file as the same name as the class with the suffix “-context.xml“. For example,
Using
?
1
2
3
4
5
6
7
package com.gordondickens.sample;
@ContextConfiguration
public class UtilsTest {
  ...
}
...
Is equivalent to
?
1
2
3
  ...
@ContextConfiguration("classpath:/com/gordondickens/sample/UtilsTest-context.xml")
  ...


 Read more...

Tuesday, January 18, 2011

Enterprise Integration with Spring Training

Are you a Spring Developer?

Do you have Enterprise solutions to develop or architect?



Chariot Solutions, a Spring Training Partner and Philadelphia leader in Spring Training, Mentoring and Consulting can help you take your Spring skills to the next level - Enterprise Integration!

There are many Spring developers who have learned by experimenting, reading documentation and maybe code dives into an existing application or two. But with the knowledge you gain from Official SpringSource training at Chariot from our certified SpringSource instructors, you can be more equipped to chose the right tools for your complex integration solutions.

The Enterprise Integration with Spring (EIwS) course is not only extremely valuable to any Spring developer it should be REQUIRED for anyone architecting Spring applications.

What is cool in the EIwS course?

  • Synchronous & Asynchronous Processing
  • Messaging with Enterprise Integration Patterns
  • Messaging with JMS
  • Exposing Services with RMI, HTTP
  • Web Services with SOAP, REST and WS Security - and why REST is cool!
  • Spring Local and Distributed Transaction Management - JTA/XA - Open Source distributed transactions without a JEE Server
  • Service Integration with SMTP (email), File, JMS, FTP, JDBC, TCP/UDP, XMPP, etc.
  • Polling and Triggering
  • Tasks and Scheduling of Processes
  • Message Filtering, Routing, Transformation, Splitting, Aggregating, Bridging and Chaining
  • Creating Batch processes for inline or offline execution
  • Monitoring Batch process exceptions
  • Unit and Mock testing of application layers
  • Modifying Integration processes without recompiling... AWESOME Right?


One of the key take-aways from this course is knowing which tools are available to choose from and why.

What does Gordon teach?

When I teach the Core or EIwS classes, I go through the common Spring project application layers, and their respective roles and responsibilities. We discuss the tools you have within Spring and which to use to solve integration concerns. In EIwS, the course builds from common concurrency, tasks & scheduling, Messaging with JMS to the flexible power of Spring Integration and Spring Batch tool sets. I teach layering your applications focussing on the power and flexibility of Service POJOs exposing your processes in a Service Oriented Architecture (SOA) manner and keeping your POJOs - Pure business objects, un-compromised by framework or infrastructure java objects.

I am teaching EIwS February 22-25, 2010 in Philadelphia! If you come you will receive:
  • A shiny new course book
  • An Official Spring USB thumb drive with SpringSource Tool Suite, Course Documentation PDF, all the labs & solutions
  • The secret meaning of the acronym "SOA"
  • Bad humor from your instructor (if I teach you can count on it)
  • Demo's that Gordon creates (if taking my class)
  • Lunch, Coffee, Tea & soft drinks


Q&A


Q: What if I have not taken the Core Spring course?
A: It is highly recommended that you attend the Core Spring Course first. Click here to see the Course Schedule

Q: What if I am not using Spring 3 yet?
A: No problem, although the course focuses on 3.0 features, you will still get usable information for your applications.

Q: What will I learn?
A: Scroll up.

Q: What if I already have used some of the topics covered?
A: Relax during those chapters or, even better, provide your "in the trenches" experience with the class.

Q: How can I get management to pay for the class?
A: This course is Essential to my skills, to provide you with better tools to choose the right approach to solving our complex integration needs. Check Here for possible Early Bird Discounts.

Q: Where do I find out about the Enterprise Integration course?
A: Click here for SpringSource Training Site

Q: When is Gordon teaching the class?
A: Click here for the next scheduled course on February 22, 2011

Q: Is there certification for Enterprise Integration Specialist?
A: Check here for the status on Enterprise Integration Specialist Certification

Memorable Quotes:


  • "Wow, I just learned in 5 minutes what it took me 2 weeks to do in the past"
  • "A Spring Developer without
  • "Understanding the layered design of Spring applications really helps me best architect my solutions."
  • "I really needed to provide file processing into my database, glad I took this class for those implementation discussions"


So, what are you waiting for? Register NOW for Enterprise Integration with Spring!


Monday, January 17, 2011

Simple Spring Social for Twitter Friends

The Spring Social project provides us developers with an easy way to interact with Twitter, Facebook, LinkedIn & TripIt via the familiar Template objects we have used. Spring has provided Templates for convenient interaction with JDBC, REST, Hibernate, JNDI, and more.


One of the simplest social media calls is to lookup someone's Twitter friends with the TwitterTemplate.


1. Add the Spring Social project dependency to the pom.xml file


<dependencies>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-core</artifactId>
<version>${spring.social.version}</version>
</dependency>
...
</dependencies>

2. Add the Spring Milestone Repository repository to the pom.xml file



<repositories>
<repository>
<id>spring-maven-milestone</id>
<name>Spring Maven Milestone Repository</name>
<url>http://maven.springframework.org/milestone</url>
</repository><
...
</repositories>

3. Create the TwitterTemplate, and ask for friends


TwitterTemplate twitterTemplate = new TwitterTemplate();
List<String> friends = twitterTemplate.getFriends("chariotsolution");
for (String friend : friends) {
System.out.println("Friend: " + friend);
}

4. Use the code above anywhere in your application


In the next blog, I will cover how to use Open Authentication (OAuth) to perform more Twitter operations.

Simple Spring Social for Twitter Friends

Gordon Dickens recently posted on his blog some thoughts on the Spring Social project.  

The Spring Social project provides us developers with an easy way to interact with Twitter, Facebook, LinkedIn & TripIt via the familiar Template objects we have used. Spring has provided Templates for convenient interaction with JDBC, REST, Hibernate, JNDI, and more.
One of the simplest social media calls is to lookup someone’s Twitter friends with the TwitterTemplate.
Read more..