Category Archives: spring data

Spring Boot is still a gem…waiting to be discovered

devnexusLast week, I had the good fortune of speaking twice at the DevNexus conference, the 2nd largest Java conference in North America. It was awesome! Apart from being a total geek fest with international attendance, it was a great place to get a bigger picture of the state of the Java community.

intro-to-spring-data-devnexus-2016A bunch of people turned up for my Intro to Spring Data where we coded up an employee management system from scratch inside of 45 minutes. You can see about 2/3 of the audience right here.

It was a LOT of fun. It was like pair programming on steroids when people helped me handle typos, etc. It was really fun illustrating how you don’t have to type a single query to get things off the ground.

platform-spring-bootWhat I found interesting was how a couple people paused me to ask questions about Spring Boot! I wasn’t expecting this, so it caught me off guard when asked “how big is the JAR file you’re building?” “How much code do you add to make that work?” “How much code is added to support your embedded container?”

learning-spring-bootSomething I tackled in Learning Spring Boot was showing people the shortest path to get up and running with a meaningful example. I didn’t shoot for contrived examples. What use is that? People often take code samples and use it as the basis for a real system. That’s exactly the audience I wrote for.

People want to write simple apps with simple pages leveraging simple data persistence. That is Spring Boot + Spring Data out of the running gate. Visit and get off the ground! (Incidentally, THIS is what my demo was about).

I-heart-spring-AidenI was happy to point out that the JAR file I built contained a handful of libraries along with a little “glue code” to read JAR-within-a-JAR + autoconfiguration stuff. I also clarified that the bulk of the code is actually your application + Tomcat + Hibernate. The size of Boot’s autoconfiguration is nothing compared to all that. Compare that to time and effort to write deployment scripts, maintenance scripts, and whatever else glue you hand write to deploy to an independent container. Spring Boot is a life saver in getting from concept to market.

It was fun to see at least one person in the audience jump to an answer before I could. Many in the audience were already enjoying Spring Boot, but it was fun to see someone else (who by the way came up to ask more questions afterward) discovering the gem of Spring Boot for the first time.

CedricTo see the glint in someone’s eye when they realize Java is actually cool. Well, that’s nothing short of amazing.

.@ScrivenerApp – The Ultimate #NoSQL Database

Over the past year, I have dove head first into use Scrivener for my writing efforts. The thing is amazing!

Scrivener is a writer’s tool, built by writers for writers. It costs about $30+. I couldn’t put my finger on what was so cool about it until I read this.

tl;dr – Scrivener puts your story/case/project into a database, Microsoft Word puts what you’re doing into a typesetter. Typesetters optimize for printout, databases optimize for reading/writing/updating information.

NoSQL Database

NoSQL data stores have gained big popularity over the past ten years. Why? Their charm is being schema-less.

schema-less – data not required to adhere to a certain structure

For years, people have adhered to SQL, the codified and accepted standard for grouping data to a strong structure. SQL comes loaded with lots of promises, which it indeed delivers. What is that?

If you define the structure of your data upfront, and observe other related practices (like 3rd Normal Form, i.e. 3NF; ACID, …), your data store will…

  • have maximum efficiency in storage by not duplicating data
  • have maximum efficiency in maintenance by not accidentally updating data in one place but forgetting to update in another place
  • get ALL the results when you query the database
  • ensure ALL inputs are committed to the database or none

These sound great, until you reach the era we have entered. People have discovered that all the guarantees of schema-driven data have costs. And costs that are proportional to your volume of data can catch up and cripple you.

We have discovered that not ALL data needs this amount of guarantee. Different data stores optimize in other ways, solving different problems. And thus was born the schema-less data store revolution.

Scrivener as a NoSQL data store


left – binder of folders with leaves; right – one leaf

How does Scrivener work? Out-of-the-box, it has a hierarchical nature. You can create folders within folders with folders. Each folder can have metadata about the folder itself, and it can contain leaves as well.

Click on a folder and you can view/edit all its leaves at once. Click on a leaf, view and edit a single leaf.

Folders and leaves can be converted from one to the other. The only difference is that folders are also containers, able to hold more folders/leaves.

The content can be text (our primary medium as writers) or other types (PDF, images, videos, …), meaning folders don’t have to just contain your story. Use it to capture your research, character notes, whatever!

Breaking out of the box

scrivener-charactersWhen you first install Scrivener, it comes with a pre-written manuscript and a tutorial. You walk through it, learning how to use the tool. It’s really quite clever and brought me up to speed, fast!

But at some point, you need to break out of conventions and learn how to use the tool. I first did so when I needed to sift through an extensive critique from my editor.

In the span of a 2-hour phone call, I had written down two pages of notes in a LibreOffice document last year. Some points, high level; some points, specific to a single sentence. I imported that document into Scrivener and took it apart, using another structure.

scrivener-researchI split up the collection of notes into individual leaves, all contained in a single folder. This way, as I addressed each comment, I could flag it as complete inside scrivener (I used checkbox icon to indicate this).

I put the scene-specific notes in a sub-sub-folder. To tackle the fact my editor had a different version of my manuscript, I dug that copy out of email and put in there as well. Using that, I tracked down every page specific comment and found its current scene.

Scrivener lets you put links between scenes (kind of like a MongoDB DBRef).

In a nutshell, I laid out my own structure, and then bent it as needed. Instead of bumping into it, like one often does with schema-based data stores, Scrivener accommodated my needs.

Spring Data Scrivener?

As a member of the Spring Data team, I’m truly amazed at how this release train of projects has leaped over the balkanized landscape of query languages. Use them when needed, but offloading typical queries to a framework is great!

I may have to keep my eye on the potential for writing apps that can query Scrivener manuscripts. It would lean on exactly what people are putting in their projects.

Until then, I hope you poke your nose into Scrivener and see how it’s perhaps the most user friendly NoSQL data store put out there to solve a very popular problem.

The state of Spring so far…

I-heart-spring-AidenI have never been more excited to be a part of the Spring team as I am now. It feels like we are blazing new trails left and right. Seeing the massive turnout this week for Stephane and Brian’s “Spring Boot University”, a 3-hour session at DevoxxFR, left me awestruck. Wish I could have been there.

Everywhere I turn, people are gobbling up Spring Boot. They tell me, this is what they have been looking for. How did this happen? It’s a really neat history.

A little bit of history

The Spring Framework started lean and mean. It was a fantastic way to integrate critically needed tools through its profound power of dependency injection. Some people criticized this as hype, but the community’s massive adoption proved the vitality of this approach. Coding was fun! Demo apps are one thing, but people were using Spring Framework to build large, complex systems. Complex systems need lots of components. Existing APIs like JMS, JDBC, and other things came with the need for lots of plumbing. These APIs were way too low level. And thus was born JmsTemplate, HibernateTemplate, and my personal favorite: JdbcTemplate.

But that was not all. Building web apps with Spring MVC was hot. It made testing app controllers nice and easy. You weren’t obligate to run web-based acceptance tests through complex controls. Instead, you could isolate things. Nonetheless, as the needs of the community grew, so did Spring. To help different parts of Spring grow and evolve and now slow down the core framework. other projects were formed. Spring Security, Spring Data, Spring Integration, Spring Batch, and more. At one point, people expressed their dislike for “spring.jar” containing everything. The Spring team chopped things up into finer grained JARs so you could grab what you needed. Then we had too many JARs. What?!?

As the power and might of Spring grew, so did its learning curve. People were asking which project to use. How to integrate them together. What version of Spring Integration with the version of Spring Framework I’m using? How do I even start using Spring MVC? What steps do I need to carry out?

Spring Boot is born

platform-spring-bootThus was born Spring Boot. Spring Boot brought forth a series of critical concepts.

  • Pre-pick the versions of Spring and other libraries so you don’t have to
  • Auto-configure boilerplate stuff like Spring MVC, Security, Integration, etc.
  • Remove key beans if you define your own
  • Accelerate Spring’s power of externalization of properties to Warp Factor 9!
  • Add on DevOps-ready metrics

A big hurdle was mixing together different libraries. If I have Spring Framework 4.0.1, what version of Spring Integration should I pick? Simple: pick one version of Spring Boot, and both of those dependencies are pre-picked for you. Boot doesn’t stop there. It extends into lots of key 3rd party libraries. This decision was so popular, that Spring IO was created to reach out and harmonize the versioning of 380+ libraries.

A big issue (especially for me, a non-web guy at the time), was standing up Spring MVC. First, you had to put certain bits into web.xml. Then you needed to stand up view resolvers, message converters, controllers, and a whole cadre of other components. You really needed to understand Spring MVC to do it and to do it right. Spring Boot stepped up to the plate and said, “don’t worry, we’ve got you covered”. Add “spring-webmvc” to your project, and Boot will create all that stuff for you. You just create a controller that returns view names, and you’re up and running.

danielskullNo form of automation can ever cover every circumstance. Sooner or later, developers need to break out of the framework’s default position. And this is where LOTS of tools fail on a massive scale. There are two common outcomes: 1) Don’t permit such customization and hamstring future developers or 2) Add so many extension points that the simple use case vanishes. Spring Boot introduces option 3) Drop bits of auto-configured stuff when you create your own. This is known as backing off, and has moved the bar forward on app and framework development really far. New applications and new frameworks will surely adopt this approach to expansion because it just makes sense. If you build a framework and don’t shoot for this, someone starting after you might catch up and pass you because they will.

Something I’ve needed for years before I wrote Java for my day job was externalization of application properties. I dealt with development, test, and production environments. Rebuilding apps for each target was wasteful. So I hand wrote code for that. Spring Framework has always had powerful support for properties files, but Spring Boot took that feature and accelerated the options. Having APP_ENV and -Dapp.env both map to @Value(“${app.env}”) String appEnv or class ApplicationProperties { public void setAppEnv(String env)… } is sheer genius can cannot be understated. People talk about 12-factor apps and high tech wwizbang manifestos, but this concept is simple to grok and applicable just about everywhere. You could be running a close network solution (which I did at my old job) with no cloud involvement and find this technique the Right Thing To Do.

DevOps-ready controls and metrics is something area always begging for. System administrators, program managers, business analysts, and others are always asking for this extra metadata about our apps. Being able to spit out a first cut of this by simply adding one dependency to an application is phenomenal. Then being able to craft your own metrics and controls with little effort ramps your app up to production ready and Management Friendly by providing them the warm fuzzy metrics for clients without breaking the bank of technical debt.

Where are things now?

With Spring Boot spreading across the Java ecosystem over the past two years, it really is exciting to see how much fun people are having building apps. They focus on the end game, not setting up infrastructure. Hearing chatter like “Using Spring Boot is like pair programming with the Spring team” (@starbuxman) and “Spring Boot is just what we need” is cool. I get excited to go the Nashville JUG and talk about some piece of Spring, not just because it “looks good”, but because I can sincerely point out how using it is simply fun! Isn’t that what real software is supposed to be? Functional, carries business value, and at the same time, fun to build and release? It almost feels like Spring Boot introduces yet another rennaisance to application development.

3021OS_mockupcover_normalI have been quite pleased that my previous book, Python Testing Cookbook has earned double the advance over the past three years (and keeps making me money!) But I jumped out of my chair when the first statement for Learning Spring Boot came in last month and showed that over 400 people had bought a copy. My excitement to write about Spring Boot was paralleled by my instinct that people would want to learn about Boot’s secrets.

There is a lot of action happening in the Spring team as we continue to blaze trails we couldn’t foresee five years ago. Many of our key decisions in the past have put us on a strong  footing to continue pushing the envelope for the future in both application power as well as ease of development. The community experience of putting out new features, getting feedback, and generally building something better each and everyday that helps thousands of people solve problems is both inspiring and humbling. There’s no other place I’d rather be working.

Happy coding!

Sprinkling in some @SpringData #REST to chapter 4 of Learning #SpringBoot /cc @PacktPub

learning-spring-boot-ch-4As I hack away at the last couple sections of chapter 4 of Learning Spring Boot, I have enjoyed being able to sprinkle in a little Spring Data REST. That project is really neat. I think it’s the way of the future for many apps out there. By providing an incredibly easy point of access to data, built on lots of standardized conventions, it’s impressive how it provides a good RESTful API while also mixing nicely with the data access layer.

Spring Data is a great way to skip over writing boilerplate CRUD functionality. Spring Data REST provide a powerful, hypermedia-driven RESTful way to interact with it. It sets you up to easily create modern front ends to interact with it.

I knew when I staked out this chapter in my proposal that I would include a section about Spring Data REST. I can’t pass up the chance to get the word out. With only a week until the first draft of chapter four is sent in to Packt, I need to knock out the last bits of this chapter and then gear up for chapter 5, Securing your Spring Boot App.


Hear about #REST and #hypermedia with #mobile UI @springone2gx this year! #s2gx


Spring Mobile/Android guru Roy Clarkson and I are giving a talk at SpringOne this year. We will be mixing Spring Data with RESTful APIs.

Roy and I have been working on a demo app that let’s you snap pictures and then upload them to a centralized web site through a simple RESTful API using hypermedia. The code to build the back end is über easy and lets you focus on the problem you’re trying to solve. On top of that, we’re building some functionality to then tweet your pic to all your friends.

spring-a-gram-catOriginal idea, huh? (See video below for my inspiration!)

The focus of our talk is about the powerful role hypermedia plays in creating flexible APIs, and how Spring Data REST puts you in control of building multiple clients. We will have a desktop web site as well as a mobile UI. We are also plotting to release the app on Cloud Foundry so you can go around and take pics during the conference and tweet them to your friends and colleagues.

Don’t forget. Early bird registration ends August 9th and will go up $150, so sign up now!

Chapter 4: Data Access with #SpringBoot on the move /cc @PacktPub

learning-spring-boot-ch-4I’ve gotten things moving quickly with chapter 4 of Learning Spring Boot. The general idea is that I want to show how to get off the ground super fast using Spring Boot and H2 as an in-memory database. Give the user the tools to either load up some sample data with a SQL script or with the Spring Data APIS. And then from there, see how to transition to production data.

You see, a common problem people deal with is building code on their development workstation and wanting to write unit tests. But the database is a fixed source of data. What do you do? Wipe it clean before every test run? What about other developers? That’s where in-memory, local database really shine. They are fast, have zero setup, and when you shutdown the test app or test case, everything is clean.

So using that to write code, test cases, etc., is great. But eventually, you have to switch over to pointing at a development database, perhaps a test bed database, and ultimately, a production database. Your app shouldn’t have to go through crazy gyrations and edits to move between those different environments.

And that’s the story I want to tell in this chapter. Spring Boot + Spring Data + Spring Framework makes this so incredibly easy. It’s a problem I ran into several times in the past, and with the über awesome power of Spring Boot+Data+Framework, I want to show my readers that there is no reason to fear the multi-environment database setup!