DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Java, Spring Boot, and MongoDB: Performance Analysis and Improvements
  • Auto Logging in Class and Method Level Using Custom Annotations in Spring Boot App
  • Smart Dependency Injection With Spring: Assignability (Part 2 of 3)
  • Extending Swagger and Spring Doc Open API

Trending

  • Hugging Face Is the New GitHub for LLMs
  • Breaking Down Silos: The Importance of Collaboration in Solution Architecture
  • Understanding Europe's Cyber Resilience Act and What It Means for You
  • Message Construction: Enhancing Enterprise Integration Patterns
  1. DZone
  2. Coding
  3. Frameworks
  4. JavaConfig Support in the Spring Tool Suite

JavaConfig Support in the Spring Tool Suite

Pieter Humphrey user avatar by
Pieter Humphrey
CORE ·
Jul. 19, 13 · Interview
Like (0)
Save
Tweet
Share
6.66K Views

Join the DZone community and get the full member experience.

Join For Free
martin lippert

originally authored by martin lippert

spring applications that use javaconfig instead of xml become more and more popular. today we would like to show you the new features in the latest spring tool suite 3.3.0 release that make it easier for you to program spring applications using annotations and javaconfig instead of xml.

project configuration

lets assume you implement a web application based on spring and javaconfig. a common practice would be to have a base @configuration class where you define the common base spring configuration in your application. that might look like this:

@configuration
@componentscan(basepackages = "org.springsource.restbucks", includefilters = @filter(service.class), usedefaultfilters = false)
class applicationconfig {

	@autowired
	private environment env;

…

in addition to that you might have an web initializer implementation for the web application that defines your common base configuration class as root config and another one (maybe an inner class of this web initializer) for the web app specific configuration:

    @configuration
    @import(repositoryrestmvcconfiguration.class)
    @componentscan(basepackages = "org.springsource.restbucks", excludefilters = @filter({ service.class, configuration.class }))
    public static class webconfiguration extends webmvcconfigurationsupport {
 
        @autowired
        repositories repositories;
 
        @bean
        public domainclassconverter domainclassconverter() {
            return new domainclassconverter<>(mvcconversionservice());
        }
...

the spring tool suite now provides the option to configure those @configuration classes directly as spring configs in the preferences of the project:

this is exactly the same as for xml-based spring config files. you could even have both configured for a project, but that doesn’t seem to be a good design choice. if you have xml files as entry points into your spring application that use the context:component-scan element to take @configuration classes into account, you don’t need to configure those classes in the project settings as well. they are recognized by the tooling automatically.

having the @configuration classes configured in the project settings, you can browse the spring model in the spring explorer or the project explorer.

bean config sets

in the same way you arrange your xml configurations into bean config sets in the tooling (to arrange them into a meaningful context for validations), you can choose to add javaconfig classes to those config sets as well.

this is particularly useful if you use multiple bean profiles. in that case you can configure a config set per profile to get the validations for each profile.

spring project settings made easy

since version 3.3.0 the spring tool suite provides an easier way to configure your spring projects for the tool support. there are new context menu actions to define @configuration classes in the project settings, remove them again, and arrange them into bean config sets:

validations

the spring tooling runs a lot of validations against your spring code and your spring configuration files in the background as part of the project build. if you have your @configuration classes defined in your project settings, those validations are running against those configs as well. this provides you, for example, validation against the @autowired annotation. whenever you have no matching bean defined in your project that would get injected at runtime, the tooling will flag this as a warning.

content assist for spring annotations

while eclipse already provides good content assist for many situations, it doesn’t know about specifics of the annotations you use to configure spring. but we do. therefore we started to support spring-specific annotations with improved content assist. as a starting point, from now on, you get content assist for type names and package names in the @componentscan annotation when defining base packages and/or basepackagetype attributes.

we will continue this work and add more support of this kind. if you would like to see something specific being implemented in this area, let us know. your feedback is welcome.

navigation for @autowired

eclipse provides a nice feature called hyperlinking. it turns class names and all kinds of elements of your java code into hyperlinks if you hold down the command key and hover over that element. we enhanced this quick navigation to provide direct access to injected beans for @autowired fields and parameters. this way you can directly jump to the bean definition of the bean that gets injected into this @autowired target.

what’s next

at the moment you have to define @configuration classes in your project settings manually. this will change in future versions. we are working on automation in this area.
in addition to that we also look into advanced support for @enable… annotations. the goal is to provide more detailed information about what beans get created because of these annotations.

wrapping up

the spring tool suite 3.3.0 supports javaconfig based spring projects as a first-class citizen and we hope you enjoy it. if you have any feedback, please do not hesitate to contact us at the forum or file a ticket (not just for bugs, but for enhancement requests as well) in our jira for sts . your feedback is always very welcome and highly appreciated. enjoy the new version of the spring tool suite.



Spring Framework Web application Content assist Annotation

Published at DZone with permission of Pieter Humphrey, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Java, Spring Boot, and MongoDB: Performance Analysis and Improvements
  • Auto Logging in Class and Method Level Using Custom Annotations in Spring Boot App
  • Smart Dependency Injection With Spring: Assignability (Part 2 of 3)
  • Extending Swagger and Spring Doc Open API

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: