刚开始JavaWeb的开发,用了SpringMVC+Mybatis的结构,按着教程来的,但是运行欢迎页能看到,但是报了Injection of resource dependencies failed.错误,Dao没找到。
这是工程的结构。
这是applicationContext.xml的配置。
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="classpath:jdbc.properties"/>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${driver}"/>
<property name="jdbcUrl" value="${url}"/>
<property name="user" value="${username}"/>
<property name="password" value="${password}"/>
<property name="maxPoolSize" value="30"/>
<property name="minPoolSize" value="10"/>
<property name="autoCommitOnClose" value="false"/>
<property name="checkoutTimeout" value="1000"/>
<property name="acquireRetryAttempts" value="2"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:mybatis-config.xml"/>
<property name="typeAliasesPackage" value="com.laxus.photoaesthetic.entity"/>
<property name="mapperLocations" value="classpath:mapper/UserDao.xml"/>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
<property name="basePackage" value="com.laxus.photoaesthetic.daos"/>
</bean>
配置有问题,没有添加自动扫描实体包
Dao没找到。
xml中配置一下,把相应的文件写进去
整个项目通过xml找文件
spring 的依赖注入配置的有问题吧,,
估计controller里面调用了dao的方法,可是你没有将你的UserDao注入进去