> For the complete documentation index, see [llms.txt](https://www.pranaypourkar.co.in/the-programmers-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pranaypourkar.co.in/the-programmers-guide/spring/core-concepts/spring-annotations/commonly-used-annotations/spring-boot-specific.md).

# Spring Boot Specific

## About

Spring Boot provides several annotations that simplify configuration, auto-configuration, and conditional bean loading.

## **1. Core Spring Boot Annotations**

These annotations help in configuring and bootstrapping a Spring Boot application.

### **`@SpringBootApplication`**

* This is the main entry point for a Spring Boot application.
* It is a combination of:
  * `@Configuration` – Marks the class as a Spring configuration class.
  * `@EnableAutoConfiguration` – Enables automatic configuration based on dependencies.
  * `@ComponentScan` – Scans for components in the same package and sub-packages.

```java
@SpringBootApplication
public class MyApplication {
    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }
}
```

### **`@EnableAutoConfiguration`**

* Enables Spring Boot’s auto-configuration feature, which automatically configures beans based on the classpath.
* It is included in `@SpringBootApplication`.

```java
@Configuration
@EnableAutoConfiguration
public class MyConfig {
}
```

## **2. Conditional Annotations**

These annotations conditionally enable or disable beans based on various criteria.

### **`@ConditionalOnProperty`**

* Loads a bean only if a specified property exists in `application.properties` or `application.yml`.

```java
// If feature.enabled=true, MyFeature bean is created.
@ConditionalOnProperty(name = "feature.enabled", havingValue = "true")
@Bean
public MyFeature myFeature() {
    return new MyFeature();
}
```

### **`@ConditionalOnClass`**

* Loads a bean only if a specified class is present in the classpath.

```java
// If ExternalLibrary is available, myService() is registered.
@ConditionalOnClass(name = "com.example.ExternalLibrary")
@Bean
public MyService myService() {
    return new MyService();
}
```

### **`@ConditionalOnMissingBean`**

* Registers a bean only if no other bean of the same type exists.

```java
// If MyService is already defined elsewhere, this bean won’t be created.
@Bean
@ConditionalOnMissingBean(MyService.class)
public MyService defaultService() {
    return new MyService();
}
```

### **`@ConditionalOnBean`**

* Registers a bean only if another specified bean exists.

```java
// MyService is created only if MyDependency is present.
@Bean
@ConditionalOnBean(MyDependency.class)
public MyService myService() {
    return new MyService();
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://www.pranaypourkar.co.in/the-programmers-guide/spring/core-concepts/spring-annotations/commonly-used-annotations/spring-boot-specific.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
