我正在使用Jboss Fuse 6.2.0并尝试从我的项目建立一个jdbc连接.我正在使用blueprint.xml来定义postgresql数据源,我正在尝试将数据插入到我的系统本地托管的数据库中.这是我在blueprint.xml中的代码:bean id=dataS...
我正在使用Jboss Fuse 6.2.0并尝试从我的项目建立一个jdbc连接.我正在使用blueprint.xml来定义postgresql数据源,我正在尝试将数据插入到我的系统本地托管的数据库中.这是我在blueprint.xml中的代码:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://localhost:5432/database-name"/>
<property name="username" value="admin"/>
<property name="password" value="admin"/>
</bean>
<bean id="transactionManager" class="com.example.TransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
我在下面添加这些依赖项来使用它.下面是我的pom.xml的代码:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1200-jdbc41</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.enterprise</artifactId>
<version>4.2.0</version>
</dependency>
当我尝试在容器(Karaf)中部署我的应用程序时,我收到此错误.找到下面的堆栈跟踪:
> org.osgi.service.blueprint.container.ComponentDefinitionException:
> Error setting property: PropertyDescriptor <name: driverClassName,
> getter: null, setter: [class
> org.springframework.jdbc.datasource.DriverManagerDataSource.setDriverClassName(class
> java.lang.String)]
> at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:941)[21:org.apache.aries.blueprint.core:1.4.2]
> at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:907)[21:org.apache.aries.blueprint.core:1.4.2]
> at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:888)[21:org.apache.aries.blueprint.core:1.4.2]
> at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:820)[21:org.apache.aries.blueprint.core:1.4.2]
> at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)[21:org.apache.aries.blueprint.core:1.4.2]
> at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)[21:org.apache.aries.blueprint.core:1.4.2]
> at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_45]
> at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)[21:org.apache.aries.blueprint.core:1.4.2]
> at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:245)[21:org.apache.aries.blueprint.core:1.4.2]
> at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:183)[21:org.apache.aries.blueprint.core:1.4.2]
> at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:682)[21:org.apache.aries.blueprint.core:1.4.2]
> at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:377)[21:org.apache.aries.blueprint.core:1.4.2]
> at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:269)[21:org.apache.aries.blueprint.core:1.4.2]
> at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_45]
> at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_45]
> at org.apache.aries.blueprint.container.ExecutorServiceWrapper.run(ExecutorServiceWrapper.java:106)[21:org.apache.aries.blueprint.core:1.4.2]
> at org.apache.aries.blueprint.utils.threading.impl.DiscardableRunnable.run(DiscardableRunnable.java:48)[21:org.apache.aries.blueprint.core:1.4.2]
> at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_45]
> at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_45]
> at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)[:1.8.0_45]
> at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)[:1.8.0_45]
> at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_45]
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_45]
> at java.lang.Thread.run(Thread.java:745)[:1.8.0_45]
> Caused by: java.lang.IllegalStateException: Could not load JDBC driver class [org.postgresql.Driver]
> at org.springframework.jdbc.datasource.DriverManagerDataSource.setDriverClassName(DriverManagerDataSource.java:150)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_45]
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_45]
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_45]
> at java.lang.reflect.Method.invoke(Method.java:497)[:1.8.0_45]
> at org.apache.aries.blueprint.utils.ReflectionUtils$MethodPropertyDescriptor.internalSet(ReflectionUtils.java:628)[21:org.apache.aries.blueprint.core:1.4.2]
> at org.apache.aries.blueprint.utils.ReflectionUtils$PropertyDescriptor.set(ReflectionUtils.java:378)[21:org.apache.aries.blueprint.core:1.4.2]
> at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:939)[21:org.apache.aries.blueprint.core:1.4.2]
> ... 23 more
> Caused by: java.lang.ClassNotFoundException: org.postgresql.Driver
> at java.net.URLClassLoader.findClass(URLClassLoader.java:381)[:1.8.0_45]
> at java.lang.ClassLoader.loadClass(ClassLoader.java:424)[:1.8.0_45]
> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)[:1.8.0_45]
> at java.lang.ClassLoader.loadClass(ClassLoader.java:357)[:1.8.0_45]
> at java.lang.Class.forName0(Native Method)[:1.8.0_45]
> at java.lang.Class.forName(Class.java:348)[:1.8.0_45]
> at org.springframework.jdbc.datasource.DriverManagerDataSource.setDriverClassName(DriverManagerDataSource.java:147)
> ... 30 more
以下是我的容器上安装的软件包列表:
hawtio :: project (1.4.0.redhat-133)
JBoss Fuse :: Support :: Fabric8 (1.2.0.redhat-133)
hawtio :: Red Hat Fuse Branding (1.4.0.redhat-133)
jsr311-api (1.1.1)
Apache ServiceMix :: Bundles :: jdom (1.1.0.4)
Apache ServiceMix :: Bundles :: oro (2.0.8.6)
Apache ServiceMix :: Bundles :: ant (1.7.0.6)
camel-velocity (2.15.1.redhat-620133)
wrap_mvn_org.springframework_spring-jdbc_3.2.3.RELEASE (0)
osgi.enterprise (4.2.0.201003190513)
我无法部署我的捆绑包.我添加了postgres作为依赖项.有人能告诉我如何使这项工作?
解决方法:
DriverManagerDataSource在OSGi中不能很好地工作.它使用了一个无法看到postgres驱动程序的类加载器.
相反,你应该使用pax jdbc.
它允许在简单的配置中定义DataSource,并自动添加池和XA支持.然后,您可以将DataSource用作OSGi服务.
不幸的是,pax-jdbc-postgresql功能中存在一个小错误.所以你必须单独安装postgresql驱动程序:
install -s mvn:org.postgresql/postgresql/9.4-1200-jdbc41
本文标题为:java – postgresql驱动程序没有被OSGI容器加载?
基础教程推荐
- Java数据结构之线段树中的懒操作详解 2023-06-06
- 解决Jackson解析嵌套类问题(MismatchedInputException) 2022-12-07
- Java时间处理第三方包Joda Time使用详解 2023-03-06
- Spring MVC整合Kaptcha的具体使用 2023-02-10
- 用Java实现简单画板功能 2022-12-27
- SpringMVC深入讲解文件的上传下载实现 2023-01-23
- 聊聊maven与jdk版本对应关系 2023-08-10
- 工厂方法在Spring框架中的运用 2023-06-23
- Spring自定义注解配置简单日志示例 2023-07-15
- 浅谈@FeignClient中name和value属性的区别 2023-02-11