2014-06-20 70 views
2

Hay無法連接到數據庫mysql 我在Windows 8上使用spring工具套件和phpMyAdmin與xampp 64NoSuchBeanDefinitionException:沒有定義[javax.activation.DataSource]類型的唯一bean:期望的單一bean但發現0:

這是我的例外:

Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.activation.DataSource] is defined: expected single bean but found 0: 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:271) 
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1083) 
at pl.bnsmedia.tasks.Runner.main(Runner.java:32) 

我在APP-context.xml的配置

<?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:context="http://www.springframework.org/schema/context" 
xmlns:p="http://www.springframework.org/schema/p" 
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

<description>Example configuration to get you started.</description> 

<context:component-scan base-package="pl.bnsmedia.tasks" /> 
<context:property-placeholder location="classpath:META-INF/spring/service-config.properties"/> 

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" 
p:url="jdbc:mysql://localhost:3306/taskManager" 
p:driverClassName="com.mysql.jdbc.Driver" 
p:username="root" 
p:password="sokol" 

/> 

我有mysql-connecor和彈簧JDBC

我試圖做一個簡單的代碼,如:

ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/app-context.xml"); 
    DataSource dataSource = context.getBean(DataSource.class); 
    System.out.println(dataSource); 

的後,我有一個例外,請幫助

回答

4

像這樣做:

javax.sql.DataSource dataSource = context.getBean(javax.sql.DataSource.class); 

您正在使用錯誤的數據源:例外說javax.activation.DataSource

+0

謝謝你正常工作 – mike

相關問題