Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

448
Visualizações
Can I start with a spring boot application without the annotations componentscan,autoconfiguration,configuration,springbootapplication?

I have written some code in order test integration with mongoDB. Please find the link to the main method for running this spring boot application below,

https://github.com/siva54/simpleusercontrol/blob/master/src/main/java/com/siva/UserManagementApplication.java

From what I have read, An application should contain any of the configurations from the following URL to declare how the applications manages the context,

http://docs.spring.io/autorepo/docs/spring-boot/current/reference/html/using-boot-using-springbootapplication-annotation.html

I haven't used any of those contexts, However my application works fine and I'm able to run it without any issues. Am I missing something here? Can you please help with the info of how my application is able to start and manage the context/dependencies automatically?

Thanks in advance

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

@SpringBootApplication is equivalent of @Configuration, @EnableAutoConfiguration and @ComponentScan. Let's consider why your application works without of any of this three annotations.

Why it works without @Configuration:

When Spring will scan packages, it will find all classes marked by @Configuration and will use them as part of configuration. But in next line you manually passed UserManagementApplication as configuration source:

SpringApplication.run(UserManagementApplication.class, args);

So spring doesn't need to find this class by scan. Therefor it is not necessary to mark it by @Configuration.


Why it works without @ComponentScan:

Class UserManagementApplication has @ImportResource("classpath:spring/application-context.xml") annotation. That means file spring/application-context.xml will be included into configuration. And this file contains next line:

<context:component-scan base-package="com.siva.*" />

So, you don't need use annotation for scan packages, because you already declared it in the xml file.


Why it works without @EnableAutoConfiguration:

This annotation allows to Spring to try guess and configure the components automatically. For example, if you include the following dependency in your build.gradle:

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-data-mongodb'
}

Spring configures all the components required to work with MongoDB automatically. And all you need just specify host and user/pass in the aplication.proprties file.

But you preferred to declare all needed beans manually in the spring/application-context.xml file. So, you simply don't need @EnableAutoConfiguration annotation at all.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda