Spring中生成DataSource bean问题

Chatopera 研发团队
企业官方账号
2009-12-05 05:52:45
环境:MySQL+Spring2.5+hibernate3.2
jdbc:mysql-connector-java-5.0.4-bin.jar
jdk: jdk1.5.0
过程:先后注入和hibernate和spring的能力,之后又反向工程下联接了数据库newvalue。
问题:hibernate设置好以后,想在applicationContext中设置datasource,取代hibernate.cfg.xml
但是,却不能在applicationContext中添加datasource bean?
下面是异常的error log
-----------------------------------------------------------------------------------------------------------
java.lang.reflect.InvocationTargetException
at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:477)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:372)
at org.eclipse.jface.wizard.WizardDialog.run(WizardDialog.java:934)
at com.genuitec.eclipse.core.portability.NewElementWizard.performFinish(NewElementWizard.java:112)
at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:742)
at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:373)
at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:624)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
at org.eclipse.jface.window.Window.open(Window.java:801)
at com.genuitec.eclipse.core.ui.wizard.WizardUtil$1.run(WizardUtil.java:32)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at com.genuitec.eclipse.core.ui.wizard.WizardUtil.launchWizard(WizardUtil.java:36)
at com.genuitec.eclipse.springframework.action.NewSpringDataSourceAction.basicRun(NewSpringDataSourceAction.java:41)
at com.genuitec.eclipse.core.ui.action.LicenseValidatingAction.run(Unknown Source)
at com.genuitec.eclipse.core.ui.action.LicenseValidatingAction.runWithEvent(Unknown Source)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:583)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:500)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2384)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2348)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2200)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:495)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:490)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:386)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
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.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
Caused by: java.lang.NullPointerException
at com.genuitec.eclipse.springframework.wizards.NewSpringBeanWizard.isPNamespaceSelection(NewSpringBeanWizard.java:90)
at com.genuitec.eclipse.springframework.wizards.NewSpringWizard.finishPage(NewSpringWizard.java:92)
at com.genuitec.eclipse.springframework.wizards.NewSpringDatasourceWizard.finishPage(NewSpringDatasourceWizard.java:60)
at com.genuitec.eclipse.core.portability.NewElementWizard$2.run(NewElementWizard.java:105)
at org.eclipse.jdt.internal.core.BatchOperation.executeOperation(BatchOperation.java:39)
at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:716)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1800)
at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:4563)
at org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:92)
at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:464)
... 46 more
Root exception:
java.lang.NullPointerException
at com.genuitec.eclipse.springframework.wizards.NewSpringBeanWizard.isPNamespaceSelection(NewSpringBeanWizard.java:90)
at com.genuitec.eclipse.springframework.wizards.NewSpringWizard.finishPage(NewSpringWizard.java:92)
at com.genuitec.eclipse.springframework.wizards.NewSpringDatasourceWizard.finishPage(NewSpringDatasourceWizard.java:60)
at com.genuitec.eclipse.core.portability.NewElementWizard$2.run(NewElementWizard.java:105)
at org.eclipse.jdt.internal.core.BatchOperation.executeOperation(BatchOperation.java:39)
at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:716)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1800)
at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:4563)
at org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:92)
at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:464)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:372)
at org.eclipse.jface.wizard.WizardDialog.run(WizardDialog.java:934)
at com.genuitec.eclipse.core.portability.NewElementWizard.performFinish(NewElementWizard.java:112)
at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:742)
at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:373)
at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:624)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
at org.eclipse.jface.window.Window.open(Window.java:801)
at com.genuitec.eclipse.core.ui.wizard.WizardUtil$1.run(WizardUtil.java:32)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at com.genuitec.eclipse.core.ui.wizard.WizardUtil.launchWizard(WizardUtil.java:36)
at com.genuitec.eclipse.springframework.action.NewSpringDataSourceAction.basicRun(NewSpringDataSourceAction.java:41)
at com.genuitec.eclipse.core.ui.action.LicenseValidatingAction.run(Unknown Source)
at com.genuitec.eclipse.core.ui.action.LicenseValidatingAction.runWithEvent(Unknown Source)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:583)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:500)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2384)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2348)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2200)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:495)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:490)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:386)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
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.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)

...全文
216 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
gshg1203 2009-12-05
  • 打赏
  • 举报
回复
你是不是想这样配置的?
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/mis"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
<property name="maxActive" value="100"></property>
<property name="maxIdle" value="30"></property>
<property name="maxWait" value="500"></property>
<property name="defaultAutoCommit" value="true"></property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/ssh/test/bean/User.hbm.xml</value>
</list>
</property>
</bean>
<bean id="userDao" class="com.ssh.test.daoImpl.UserDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="userService" class="com.ssh.test.serviceImpl.UserserviceImpl">
<property name="userDao" ref="userDao"></property>
</bean>
<bean id="saveuser" class="com.ssh.test.action.saveuserAction">
<property name="service" ref="userService"></property>
</bean>
</beans>
大川101 2009-12-05
  • 打赏
  • 举报
回复
你这个配置文件 好乱吗
datasource hibernate.cfg.xml中有
直接拷到spring配置文件中。
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 zhangyuhong 的回复:]
如果你是SSH整合,用Spring去管理struts,hibernate,
如你所说,我想你添加hibernate时候的几个选择就有问题
[/Quote]
在hibernate之后,进行了简单的测试,证明数据库是链接上了。
礼拜六 2009-12-05
  • 打赏
  • 举报
回复
如果你是SSH整合,用Spring去管理struts,hibernate,
如你所说,我想你添加hibernate时候的几个选择就有问题
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">


<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="guestbookDao"
class="com.csdner.guestbook.dao.hibernate.GuestbookDaoHibernate"
abstract="false" lazy-init="default" autowire="default"
dependency-check="default">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="guestbookManager"
class="com.csdner.guestbook.service.impl.GuestbookManagerImpl"
abstract="false" lazy-init="default" autowire="default"
dependency-check="default">
<property name="guestbookDao">
<ref bean="guestbookDao" />
</property>
</bean>
<bean name="/guestbook"
class="com.csdner.guestbook.web.action.GuestbookAction"
abstract="false" lazy-init="default" autowire="default"
dependency-check="default">
<property name="guestbookManager">
<ref bean="guestbookManager" />
</property>
</bean>
</beans>
道光2008 2009-12-05
  • 打赏
  • 举报
回复
看看你的applicationContext。xml配置
  • 打赏
  • 举报
回复
好无奈啊
wl_ldy 2009-12-05
  • 打赏
  • 举报
回复
sping的东西还没弄过,先顶一个了。。。

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧