4 Replies Latest reply on May 31, 2019 4:49 PM by rareddy

    Apparent bean collision Teiid/ Spring Boot

    dieman.one

      Hello,

       

      I am new to Teiid, trying to integrate it into myApring Boot application and face the following issue: during application startup I get the following error signalling an apparent bean collision

       

      The bean 'dataSource', defined in class path resource [org/teiid/spring/autoconfigure/TeiidAutoConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class] and overriding is disabled.

      Action:

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

       

      Since renaming doesn't seem an option, I tried allowing bean overriding, as recommended above.

      This leads to the following error:

      <long exception stack trace>

      Caused by: java.lang.ClassNotFoundException: org.springframework.boot.jta.XADataSourceWrapper

          at java.net.URLClassLoader.findClass(URLClassLoader.java:382)

          at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

          at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)

          at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

          ... 25 common frames omitted

       

      Please help clearing this out.

       

      Many thanks in advance.

        • 1. Re: Apparent bean collision Teiid/ Spring Boot
          shawkins

          > The bean 'dataSource', defined in class path resource [org/teiid/spring/autoconfigure/TeiidAutoConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class] and overriding is disabled.

           

          The way things are written now, there's an assumption that the Teiid DataSource is the primary DataSource and is given a common name.  You raise a good point as to whether that makes sense as it's a greenfield assumption.  Can you describe your circumstances more?  What in your app is already using the dataSource name?

           

          > Since renaming doesn't seem an option, I tried allowing bean overriding, as recommended above.

           

          XADataSourceWrapper should already be in your classpath if you have a dependency on teiid-spring-boot-starter.

          • 2. Re: Apparent bean collision Teiid/ Spring Boot
            rareddy

            The default datasource has no name or one with @primary annotation, and is the datasource exposed by bean from datasource() method and this data source gets wired into for any jpa or spring data framework. Here we use this to inject Teiid as primary data source. For all other sources Teiid now acts like a proxy where all calls need to go through.

             

            If you are working with existing spring boot application that means you can refractor your bean to give a specific name and configure properties accordingly. Then any access to source will be through Teiid based driver into your source. Unless you are using data source specific sql, everything else should work fine.

             

            As Steve asks, yes knowing about your restrictions about renaming we can possibly offer other options.

             

            BTW, if you are working with direct vdbs then there may be ways refactor not to use as primary datasource. But that option currently not available in code yet.

             

            Ramesh..

            • 3. Re: Apparent bean collision Teiid/ Spring Boot
              dieman.one

              Hi Steven and Ramesh,

               

              Thank you for the answers.

               

              I am simply following this tutorial: https://github.com/teiid/teiid-spring-boot/tree/master/samples/rest

              Building a Spring boot application attempting to read an existing REST web service as a JDBC data source. I have defined the bean, service etc - just like in the tutorial. Nothing fancy. With these minimal features I ran into the error I described in my post.

               

              As you can see from my original post, the conflict is between a Teiid's Data Source bean and a Spring Boot's DataSource bean, (not my bean) so renaming any of these beans is not an option, right? Obviously I should not try renaming Teiid's or Spring's classes.

               

              Please advise:

               

              1) should the bean overriding be enabled or not?

               

              2) If not, what are other possible ways to troubleshoot the bean collision (as we already established that bean renaming is out of question)?

               

              3) If bean overriding should be enabled, why am I facing

              java.lang.ClassNotFoundException: org.springframework.boot.jta.XADataSourceWrapper?

               

              This class is in my classpath, as you pointed out ( I am attaching my POM for reference).

              Could it be that Teeiid's classes depend Spring version where this class has been in another package or something of this sort?

               

              I have read here java.lang.ClassNotFoundException: org.springframework.boot.context.embedded.FilterRegistrationBean with Spring Boot 1.5.…  that this class has been indeed moved to another package between Spring versions.

              Could you  recommend which versions of Spring/Teiid libraries are compatible?

               

              Thanks,

              Dmitry

               

              <dependencies>

                 <dependency>

                 <groupId>org.springframework.boot</groupId>

                 <artifactId>spring-boot-starter-data-mongodb</artifactId>

                 <version>2.1.4.RELEASE</version>

                 </dependency>

                 <dependency>

                 <groupId>org.springframework.boot</groupId>

                 <artifactId>spring-boot-starter-data-jpa</artifactId>

                 <version>2.1.4.RELEASE</version>

                 </dependency>

                 <dependency>

                 <groupId>org.springframework.boot</groupId>

                 <artifactId>spring-boot-starter-jdbc</artifactId>

                 </dependency>

                 <dependency>

                 <groupId>org.springframework.boot</groupId>

                 <artifactId>spring-boot-starter-web</artifactId>

                 </dependency>

                 <dependency>

                 <groupId>org.springframework.boot</groupId>

                 <artifactId>spring-boot-starter-logging</artifactId>

                 <version>2.1.4.RELEASE</version>

                 </dependency>

                 <dependency>

                 <groupId>org.springframework.boot</groupId>

                 <artifactId>spring-boot-starter-web-services</artifactId>

                 </dependency>

                 <dependency>

                 <groupId>io.springfox</groupId>

                 <artifactId>springfox-swagger2</artifactId>

                 <version>2.6.1</version>

                 </dependency>

                 <dependency>

                 <groupId>org.springframework.boot</groupId>

                 <artifactId>spring-boot-starter-security</artifactId>

                 <version>2.1.4.RELEASE</version>

                 </dependency>

                 <dependency>

                 <groupId>org.projectlombok</groupId>

                 <artifactId>lombok</artifactId>

                 <version>1.16.18</version>

                 <optional>true</optional>

                 </dependency>

                 <dependency>

                 <groupId>com.oracle</groupId>

                 <artifactId>ojdbc7</artifactId>

                 <version>12.1.0.2</version>

                 </dependency>

                 <!-- ******* TEIID ******* -->
                 <dependency>

                 <groupId>org.teiid</groupId>

                 <artifactId>teiid-spring-boot-starter</artifactId>

                 <version>1.0.2</version>

                 </dependency>

                 <dependency>

                 <groupId>org.teiid</groupId>

                 <artifactId>spring-data-rest</artifactId>

                 <version>1.0.2</version>

                 </dependency>

              • 4. Re: Apparent bean collision Teiid/ Spring Boot
                rareddy

                Yes, the confusion I had was (and Steve too) is that I was thinking the naming collision from your data source. If you are just using the Teiid, then no there should be no collisions. As per the pom file, I suggest you take a look at one with the example, the spring version is already chosen by the "teiid-spring-boot-starter" and you can not select a different version. Also, I suggest you use "1.1.0" as that is the latest version, and it uses Spring Boot 2.1.3 version. So try removing 2.1.4.RELEASE tag and upgrade the Teiid to 1.1.0 see if the issue still exists.

                 

                Ramesh..