Spring Social Connection Keys like Facebook AppIds and Twitter Consumer Secrets are usually found in application.properties, but you might want to keep these outside of your application. I blogged about using Spring external properties before, that time using them in Thymeleaf HTML. This post will be similarly short and sweet, but I wanted to write it up to help fellow developers get up and running with NixMash Spring Social more quickly.
Let’s start with the essential SocialConfig.java source where we configure the Connection Factories. I should note that if you’re using Spring Boot and using the correct Spring Social Property Names in application.properties it’s not necessary to even include addConnectionFactories() for entering the connection keys. We’re using our External Properties file so we’re including it.
ApplicationSettings POJO Component
Our ApplicationSettings is a plain old Java object class. As a sidebar, most of the NixMash Spring Social action happens in project MVC, but ApplicationSettings is located in a referenced Project (JPA) which is a good example of cross-project Beans at work.
Notice the @ConfigurationProperties “external” prefix for property names, so the external.properties file looks something like this.