25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 17 ■ Be Social and Go Mobile<br />

In Listing 17-1, you need to add the four keys you created when you registered your Twitter application and when<br />

you generated your access token keys. These keys are needed in order to have a secure way to communicate between<br />

your application and Twitter’s REST API. Next, you need to create the XML configuration for your My Documents<br />

<strong>Spring</strong> application, as shown in Listing 17-2.<br />

Listing 17-2. mydocuments-context.xml<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Listing 17-2 shows the XML configuration that the <strong>Spring</strong> container will use in order to create the instances of<br />

your beans. First, you are creating a reference to the twitter.properties file. This reference will be a placeholder<br />

for your properties keys and their values. Then you are creating a “tweet” bean. This bean has a reference to the<br />

org.springframework.social.twitter.api.impl.TwitterTemplate class. This class has a constructor with four<br />

parameters: the consumerKey, the consumerSecret, the accessToken, and the accessTokenSecret. The values of these<br />

parameters will be the corresponding values of the placeholders you set (and that will match all the properties from<br />

the twitter.properties file).<br />

Next, you are going to create the class that will use the TwitterTemplate bean, the DocumentTweet class (shown<br />

in Listing 17-3).<br />

245

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!