1

I have a class/spring bean A inside package a.b.c in a common artifact which is imported as a dependency in my project. There is the same class A defined in my project as well but in different packages lets say x.y.z. So when I run the spring boot app, it fails with the following exception. Is there any way to exclude the component A which is present in the common library, but I need other components present in the other library. I tried excluding using regex but still the same error.

      "message": "Annotation-specified bean name 'A' for bean class [a.b.c.A] conflicts with existing, non-compatible bean definition of same name and class [x.y.z.A]",
      "name": "org.springframework.context.annotation.ConflictingBeanDefinitionException",
      "extendedStackTrace": [
        {
          "class": "org.springframework.context.annotation.ClassPathBeanDefinitionScanner",
          "method": "checkCandidate",
          "file": "ClassPathBeanDefinitionScanner.java",
          "line": 345,
          "exact": false,
          "location": "spring-context-4.3.6.RELEASE.jar!/",
          "version": "4.3.6.RELEASE"```

Deepu
  • 39
  • 1
  • 6
  • Sure there is, see https://stackoverflow.com/questions/18992880/exclude-component-from-componentscan – ekalin Dec 08 '19 at 15:12
  • ```@SpringBootApplication @ComponentScan( basePackages = {" "a.b"} , excludeFilters = { @ComponentScan.Filter(type = FilterType.REGEX, pattern = "a\\.b\\.c\\.*")``` I am excluding this way but this error is still there @ekalin – Deepu Dec 08 '19 at 15:20
  • is this something to do with spring version? – Deepu Dec 08 '19 at 17:44
  • is the class Definition the same or only the name is the same? – dassum Dec 08 '19 at 19:32
  • try @ComponentScan(excludeFilters = @Filter(a.b.c.A.class)); Also check by mistake you might have imported wrong package. – dassum Dec 08 '19 at 19:34

0 Answers0