配完spring数据源后,跑不起来.报[Error creating bean with name 'dataSource' defined in class path resource [beans-properties.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: com/mchange/v2/ser/Indirector]这个错.
配置文件是(beans-properties.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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="user" value="sa"></property> <property name="password" value="111111"></property> <property name="driverClass" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"></property> <property name="jdbcUrl" value="jdbc:sqlserver://localhost:1433;databaseName=test"></property> </bean> </beans>
代码:
public class Main { @SuppressWarnings("resource") public static void main(String[] args) throws SQLException { ApplicationContext cxt = new ClassPathXmlApplicationContext( "beans-properties.xml"); DataSource dataSource = (DataSource) cxt.getBean("dataSource"); System.out.println(dataSource.getConnection()); } }
代码中直接调配置的数据源,debug时第一行代码就过不去.
求助大神啊.
解决,少了一个jar包mchange-commons-java-0.2.3.4.jar