[align=left]这和Struts2.1.6+ibatis2.3.4.726+Spring2.5.6
jar包,都打了,启动tomcat也不会报错!
bean.xml配置如下:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/user" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocations" value="/WEB-INF/classes/SqlMapConfig.xml" />
<!-- <property name="mapperLocations" value="classpath*:/**/*.ibatis.xml"/> -->
</bean>
<!--注入sqlMapClientTemplate 想当于 继承(extends) SqlMapClientDaoSupport -->
<bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient">
<ref local="sqlMapClient" />
</property>
</bean>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="userDao" class="com.ssi.dao.impl.DaoImpl">
<property name="sqlMapClientTemplate">
<ref bean="sqlMapClientTemplate" />
</property>
</bean>
<bean id="userService" class="com.ssi.service.Impl.userServiceImpl">
<property name="dao" ref="userDao"></property>
</bean>
初始化
ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:applicationConfig.xml");
userService service = (userService) ctx.getBean("userService");
service.deleteById(1);
这里为什么初始化的时候报错!!!
【错误如下】:
Error creating bean with name 'sqlMapClient' defined in class path resource [applicationConfig.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [WEB-INF/classes/SqlMapConfig.xml] cannot be opened because it does not exist[/align]