DEV Community

Salad Lam
Salad Lam

Posted on

1

Spring Boot: how to disable build-in auto-configuration

The objective of the Spring Boot project is to pre-define essential beans for you in order to start up an application with minimum configuration. This is done by a set of auto configuration classes bundled in Spring Boot's package. And if you define a bean, Spring Boot is also able to recognize your bean, then will not create the predefined bean.

For example org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration class of spring-boot-autoconfigure:2.6.11.

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ DataSource.class, JdbcTemplate.class })
@ConditionalOnSingleCandidate(DataSource.class)
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
@EnableConfigurationProperties(JdbcProperties.class)
@Import({ DatabaseInitializationDependencyConfigurer.class, JdbcTemplateConfiguration.class,
        NamedParameterJdbcTemplateConfiguration.class })
public class JdbcTemplateAutoConfiguration {
}
Enter fullscreen mode Exit fullscreen mode

This class will enable only if

  1. DataSource and JdbcTemplate class files can be found in class path
  2. Only one DataSource bean is created

For some time, it is necessary to disable the entire auto configuration class. For example, if you want to disable an auto configuration class org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration. Just specify the annotation attribute "exclude" of org.springframework.boot.autoconfigure.SpringBootApplication annotation. i.e.

@SpringBootApplication(exclude = {HibernateJpaAutoConfiguration.class})
Enter fullscreen mode Exit fullscreen mode

And in CONDITIONS EVALUATION REPORT, you can see the class is excluded in Exclusions section.

Exclusions:
-----------
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
Enter fullscreen mode Exit fullscreen mode

Image of AssemblyAI tool

Transforming Interviews into Publishable Stories with AssemblyAI

Insightview is a modern web application that streamlines the interview workflow for journalists. By leveraging AssemblyAI's LeMUR and Universal-2 technology, it transforms raw interview recordings into structured, actionable content, dramatically reducing the time from recording to publication.

Key Features:
🎥 Audio/video file upload with real-time preview
🗣️ Advanced transcription with speaker identification
⭐ Automatic highlight extraction of key moments
✍️ AI-powered article draft generation
📤 Export interview's subtitles in VTT format

Read full post

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay