Все еще получает BeanDefinitionOverrideException после установки переопределения на true - PullRequest
0 голосов
/ 04 марта 2019

При создании проекта я получаю ошибки для моего теста.Я немного погуглил и обнаружил, что все говорят о том, что весна требует установки определения бина, переопределяющего значение true.Мои свойства уже установили переопределение bean-компонента на true, но я все еще получаю эту ошибку.Кто-нибудь знает, что мне не хватает?

Тест контроллера

@WebMvcTest(controllers = PermitController.class)
public class PermitControllerTest extends CrudControllerTest<Permit, PermitRepository> {

    @TestConfiguration
    static class Configuration {
        @Bean
        public PermitController permitController() {
            return new PermitController();
        }
    }

    @Autowired
    private PermitController permitController;

    @MockBean
    private PermitRepository permitRepository;

    @MockBean
    private AccountRepository accountRepository;

    @MockBean
    private PocRepository pocRepository;

    @MockBean
    private DateslotRepository dateslotRepository;

    @MockBean
    private TimeslotRepository timeslotRepository;

    @MockBean
    private CoordinateRepository coordinateRepository;

    // TODO: test invalid fields

    /**
     * Setup before unit tests are run.
     */
    @Before
    public void before() {
        permitController.setRepository(permitRepository);
        super.init(permitRepository);
        super.setUrl(WebConfig.PERMIT + "/");
        super.setEntities(TestEntities.getPermit(null), TestEntities.getPermit(TestEntities.ID1));
    }
}

Ошибка теста

Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'permitController' defined in com.example.permitservice.controller.PermitControllerTest$Configuration: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=permitControllerTest.Configuration; factoryMethodName=permitController; initMethodName=null; destroyMethodName=(inferred); defined in com.example.permitservice.controller.PermitControllerTest$Configuration] for bean 'permitController': There is already [Generic bean: class [com.example.permitservice.controller.PermitController]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [E:\workspace\gitpermitmanager\permitMgrService\build\classes\java\main\com\example\permitservice\controller\PermitController.class]] bound.
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.registerBeanDefinition(DefaultListableBeanFactory.java:894)
    at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:274)
    at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:141)
    at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:117)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:327)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:691)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:528)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
    at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:127)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
    ... 50 more

Свойства:

spring.profiles.active = development
spring.main.allow-bean-definition-overriding = true
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...