Announcement Announcement Module
Collapse
No announcement yet.
ClassNotFoundException: BasicDataSource Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ClassNotFoundException: BasicDataSource

    Hi! I am developing a web application by using struts 2, hibernate 3, maven 2, spring.
    I found an example that suggests using Spring to inject the sessionFactory to the dao and the example also suggests injecting this object to define information about the connection:

    <bean id="dataSource"
    class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName">
    <value>com.mysql.jdbc.Driver</value>
    </property>
    <property name="url">
    <value>
    jdbc:mysql://localhost:3306/lider
    </value>
    </property>
    .....
    </bean>

    The thing is that when I try to load my application, I am getting this exception in console:

    java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1387)
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1233)
    at org.springframework.util.ClassUtils.forName(ClassU tils.java:229)
    ......

    I have defined in my pom.xml file the required dependency for that org.apache.commons.dbcp.BasicDataSource class:

    <!-- Spring -->
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring</artifactId>
    <version>2.5.6</version>
    </dependency>
    <dependency>
    <groupId>commons-dbcp</groupId>
    <artifactId>commons-dbcp</artifactId>
    <version>1.2.2</version>
    </dependency>

    The project does not have compilation problems, the only problem is when trying to load it...

    Any ideas about this problem?

    Thanks in advance!

  • #2
    I have the same problem.
    I have a bundle that uses the org.apache.commons.dbcp.BasicDataSource and it is fine , but in tests I get
    Code:
    org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.apache.commons.dbcp.BasicDataSource] for bean with name 'dataSource' defined in URL [bundleresource://31/genericobject-context.xml]; nested exception is java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource not found from bundle [TestBundle-testOsgiPlatformStarts-test.java.genericobject.BundleTest]
    	at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1141)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:524)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1177)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:758)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:422)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
    	at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.normalRefresh(AbstractDelegatedExecutionApplicationContext.java:148)
    	at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$NoDependenciesWaitRefreshExecutor.refresh(AbstractDelegatedExecutionApplicationContext.java:73)
    	at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.refresh(AbstractDelegatedExecutionApplicationContext.java:136)
    	at org.springframework.osgi.test.AbstractOptionalDependencyInjectionTests.createApplicationContext(AbstractOptionalDependencyInjectionTests.java:107)
    	at org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:189)
    	at org.springframework.test.AbstractSingleSpringContextTests.loadContext(AbstractSingleSpringContextTests.java:169)
    	at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:140)
    	at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:98)
    	at org.springframework.osgi.test.AbstractOsgiTests.osgiSetUp(AbstractOsgiTests.java:539)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:193)
    	at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:178)
    	at org.springframework.osgi.test.internal.support.OsgiJUnitTestAdapter.osgiSetUp(OsgiJUnitTestAdapter.java:80)
    	at org.springframework.osgi.test.internal.support.OsgiJUnitService.runTest(OsgiJUnitService.java:94)
    	at org.springframework.osgi.test.internal.support.OsgiJUnitService.executeTest(OsgiJUnitService.java:71)
    	at org.springframework.osgi.test.internal.support.OsgiJUnitService.runTest(OsgiJUnitService.java:45)
    	at org.springframework.osgi.test.JUnitTestActivator.executeTest(JUnitTestActivator.java:73)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.springframework.osgi.test.AbstractOsgiTests.invokeOSGiTestExecution(AbstractOsgiTests.java:397)
    	at org.springframework.osgi.test.AbstractOsgiTests.runBare(AbstractOsgiTests.java:206)
    	at org.springframework.osgi.test.AbstractOsgiTests$1.protect(AbstractOsgiTests.java:184)
    	at junit.framework.TestResult.runProtected(TestResult.java:124)
    	at org.springframework.osgi.test.AbstractOsgiTests.run(AbstractOsgiTests.java:181)
    	at junit.framework.TestSuite.runTest(TestSuite.java:230)
    	at junit.framework.TestSuite.run(TestSuite.java:225)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
    	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
    	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
    	at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
    	at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource not found from bundle [TestBundle-testOsgiPlatformStarts-test.java.genericobject.BundleTest]
    	at org.springframework.osgi.util.BundleDelegatingClassLoader.findClass(BundleDelegatingClassLoader.java:103)
    	at org.springframework.osgi.util.BundleDelegatingClassLoader.loadClass(BundleDelegatingClassLoader.java:156)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    	at org.springframework.util.ClassUtils.forName(ClassUtils.java:211)
    	at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:385)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1138)
    	... 51 more
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource
    	at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:481)
    	at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:397)
    	at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:385)
    	at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:87)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    	at org.eclipse.osgi.framework.internal.core.BundleLoader.loadClass(BundleLoader.java:313)
    	at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:227)
    	at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1274)
    	at org.springframework.osgi.util.BundleDelegatingClassLoader.findClass(BundleDelegatingClassLoader.java:99)
    	... 56 more
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource not found from bundle [TestBundle-testOsgiPlatformStarts-test.java.genericobject.BundleTest]
    	at org.springframework.osgi.util.BundleDelegatingClassLoader.findClass(BundleDelegatingClassLoader.java:103)
    	at org.springframework.osgi.util.BundleDelegatingClassLoader.loadClass(BundleDelegatingClassLoader.java:156)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    	at org.springframework.util.ClassUtils.forName(ClassUtils.java:211)
    	at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:385)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1138)
    	... 51 more
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource
    	at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:481)
    	at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:397)
    	at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:385)
    	at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:87)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    	at org.eclipse.osgi.framework.internal.core.BundleLoader.loadClass(BundleLoader.java:313)
    	at org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:227)
    	at org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1274)
    	at org.springframework.osgi.util.BundleDelegatingClassLoader.findClass(BundleDelegatingClassLoader.java:99)
    	... 56 more
    My test pom has

    Code:
    <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>com.springsource.org.apache.commons.dbcp</artifactId>
                <version>1.2.2.osgi</version>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>com.springsource.org.apache.commons.pool</artifactId>
                <version>1.4.0</version>
            </dependency>
            <dependency>
                <groupId>commons-dbcp</groupId>
                <artifactId>commons-dbcp</artifactId>
                <version>1.2.2</version>
            </dependency>
    and my boot-bundle.properties also imports these bundles (
    Code:
    ${ignore.spring.osgi.groupId},com.springsource.org.apache.commons.dbcp,1.2.2.osgi
    ${ignore.spring.osgi.groupId},com.springsource.org.apache.commons.pool,1.4.0
    )

    Comment


    • #3
      Problem solved!

      I just solved this class not found exception by adding the dependency at:

      Project, Properties, Java EE Module Dependencies, Add Variable, M2_REPO, Extend

      Note that I am working with Eclipse as IDE.

      Comment

      Working...
      X