2

I am creating tests using JUnit. Need to mock args for creating an Environment variable.

String[] testStr = new String[]{
                "--spring.main.web-environment=false" //,
                //"--spring.autoconfigure.exclude=blahblahblah"  
                // Override any other environment properties according to your needs
        };


        //String[] testStr = new String[]{ 
        JHipsterConstants.SPRING_PROFILE_DEVELOPMENT,JHipsterConstants.SPRING_PROFILE_PRODUCTION };

        //Throwing error here
        app.main(testStr);

Method I am calling

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(TestApp.class);
        DefaultProfileUtil.addDefaultProfile(app);
        // line below fails. 
        Environment env = app.run(args).getEnvironment();
        logApplicationStartup(env);
    }

Fails on env = app.run(args).getEnvironment(). The test hesitates for several seconds and errors out. Any solutions will be appreciated. See error text below.

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'swaggerSpringfoxApiDocket', defined in class path resource [io/github/jhipster/config/apidoc/SwaggerConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [io/github/jhipster/config/apidoc/SwaggerAutoConfiguration.class] and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true


org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'swaggerSpringfoxApiDocket' defined in class path resource [io/github/jhipster/config/apidoc/SwaggerConfiguration.class]: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=io.github.jhipster.config.apidoc.SwaggerConfiguration; factoryMethodName=swaggerSpringfoxApiDocket; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [io/github/jhipster/config/apidoc/SwaggerConfiguration.class]] for bean 'swaggerSpringfoxApiDocket': There is already [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=io.github.jhipster.config.apidoc.SwaggerAutoConfiguration; factoryMethodName=swaggerSpringfoxApiDocket; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [io/github/jhipster/config/apidoc/SwaggerAutoConfiguration.class]] bound.

    at org.springframework.beans.factory.support.DefaultListableBeanFactory.registerBeanDefinition(DefaultListableBeanFactory.java:927)
    at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:287)

Stormy Weather
  • 295
  • 1
  • 4
  • 12
  • Does this answer your question? [Connect to H2 database using IntelliJ database client](https://stackoverflow.com/questions/28940912/connect-to-h2-database-using-intellij-database-client) – Turing85 Aug 24 '20 at 18:06
  • @Turing85 I don't think that is an answer. That article is about creating a H2 database. – Stormy Weather Aug 24 '20 at 19:04
  • Can you try changing your property to spring.main.web-application-type=none instead of spring.main.web-environment=false ? – SKumar Aug 24 '20 at 19:30
  • @skumar I changed it and got this error - org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'swaggerSpringfoxApiDocket' defined in class path resource [io/github/jhipster/config/apidoc/SwaggerConfiguration.class]: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=io.github.jhipster.config.apidoc.SwaggerConfiguration; – Stormy Weather Aug 24 '20 at 19:55

0 Answers0