The upcoming IntelliJ IDEA 2017.1 includes numerous features to help Spring developers. In this post, we’re going to look specifically at the feature for Spring Data. Support for Spring Data has been updated to include support for features in release train Kay.
Navigation for new Repository types
We’ve added a gutter icon for navigation to declarations of specific repository types
In this example, you can see that we’ve annotated our configuration with
@EnableReactiveCassandraRepositories. If you click on the gutter icon next to the annotation, you can see the specific Reactive implementations of the repositories.
You can, of course, click on one to be taken to its declaration. This also applies to repository fields that are autowired.
This navigation is available for: Cassandra, Couchbase, Elasticsearch, key-value repositories, Reactive Cassandra, Reactive MongoDB, Redis and Solr.
Smarter Code Completion
IntelliJ IDEA 2017.1 is now even smarter at offering you Spring-specific help. For example, you get support for creating query methods using nested properties. Let’s assume that you have a ReviewRepository, that enables you to find Reviews for a Hotel.
You may want to alter this to provide more complex searches, for example to search for a Review by the hotel’s zip code (this is the nested parameter) and the rating of the review.
You can see that IntelliJ IDEA offers you suggestions as you create this method, and can also generate the parameters for you.
IntelliJ IDEA 2017.1 also provides help for creating custom queries, code completion here helps to minimise errors.
As you’d expect, IntelliJ IDEA can also help with SQL queries you may need to write. If need to use a native query IntelliJ IDEA will help you to craft this too. Remember you need to select a SQL dialect to get full help here.
Other annotations also have had the same treatment, so you have code completion, navigation and warnings about errors on the
@Value annotation if you’re using Spring Data REST projections.
IntelliJ IDEA 2017.1 has updated inspections help to identify potential problems with query methods in repositories. For example, you will now be informed if a method name refers to fields that don’t exist on the entity, as in this case where the method refers to “surname” but the Customer has a field “lastname”.
It doesn’t stop there. Inspections will also let you know if the parameters to the method aren’t correct, as in this case here where we forgot to add firstname and lastname parameters
IntelliJ IDEA offers a quick fix for this problem of course
The inspection doesn’t just warn about missing parameters, but also incorrect parameter types
To provide full error checking, there’s a final inspection that ensures that the return type from the method is also correct
New Spring Data View
There’s a new view which shows you the Spring Data repositories
You can use this to see all your repositories and their query methods, along with the documentation for these methods. Of course, if you select one of the members, you will be taken to the code for that method.
You can choose to show the inherited members too, in order to see all the available methods.
As with all IntelliJ IDEA windows, it’s possible to easily search for the item you want by simply typing in the window.
You can also choose to simply list all the repositories without grouping them by module
And you can optionally display the repositories available from your project’s libraries
Spring Data LDAP Support
Finally, we’ve added support for the Spring Data LDAP project. This includes navigation and code completion in the XML configuration files, gutter icons for navigation, and support for @EnableLdapRepositories.
Develop with Pleasure!