Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
How to get command line argument inside BeanFactoryPostProcessor?

I am using Spring boot for my application written on Kotlin. I am able to get command line arguments using Environment.getProperty("nonOptionArgs", Array<String>::class.java)

However, inside BeanFactoryPostProcessor i cannot autowire environment - as this post-processor is running too early in the lifecycle. How I can access command line arguments inside BeanFactoryPostProcessor?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Well , you can implement your BeanFactoryPostProcessor with EnvironmentAware to get the Environment :

@Component
public class FooBeanFactoryPostProcessor implements BeanFactoryPostProcessor , EnvironmentAware{

    private Environment env;

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

            env.getProperty("nonOptionArgs");
            //I should be able to access env at here .Hehe

    }

    @Override
    public void setEnvironment(Environment environment) {
            this.env = environment;
    }

}
over 4 years ago · Santiago Trujillo Denunciar

0

From your comment :

I would like to define dynamically beans based on command argument values. Why to i do this in BeanFactoryPostProcessor - is to be sure that bean definitions are there before actual bean instantiation- so i don't need @DependsOn annotation.

In term of loading beans conditionally (like auto-configuration in spring boot), I would say that it's much cleaner to use the @ConditionalXXX annotations, most specifically the @ConditionalOnProperty.

Referencing the Java-doc for @ConditionalOnProperty here they said :

Conditional that checks if the specified properties have a specific value. By default the properties must be present in the Environment and not equal to false. The havingValue() and matchIfMissing() attributes allow further customizations.

So you can do something similar to :

@ConditionalOnProperty(prefix = "my.env", name = "var", havingValue = "true", matchIfMissing = false)
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda