spring ibatis整合出错

youfeng445 2013-07-07 02:08:15
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in file [E:\workspace_n\hx\webapp\WEB-INF\classes\com\hx\core\user\dao\impl\UserDaoImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlMapClient' is required
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1412)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4371)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
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.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.IllegalArgumentException: Property 'sqlMapClient' is required
at org.springframework.orm.ibatis.SqlMapClientTemplate.afterPropertiesSet(SqlMapClientTemplate.java:143)
at org.springframework.orm.ibatis.support.SqlMapClientDaoSupport.checkDaoConfig(SqlMapClientDaoSupport.java:109)
at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1469)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1409)
... 32 more


配置文件, 类文件 如下

public interface UserDao {

UserInfo getUserByLoginName(UserQo qo);

}

@Component("userDao")
public class UserDaoImpl extends SqlMapClientDaoSupport implements UserDao {

private final String selectUserByLoginName = "selectUserByLoginName";

@Override
public UserInfo getUserByLoginName(UserQo qo) {
return (UserInfo)getSqlMapClientTemplate().queryForObject(selectUserByLoginName, qo.getLoginName());
}

}


文件位置:
/hx/src/sqlmap/User.xml

<sqlMap> 

<typeAlias alias="user" type="com.hx.core.user.pojo.UserInfo" />

<resultMap id="UserResult" class="user">
<result property="id" column="id"/>
<result property="fullName" column="full_Name"/>
<result property="birthday" column="birthday"/>
<result property="cellPhone" column="cellPhone"/>
<result property="emailAddress" column="emailAddress"/>
<result property="location" column="location"/>
<result property="loginName" column="loginName"/>
<result property="password" column="password"/>
<result property="position" column="position"/>
<result property="createDate" column="createDate"/>
<result property="delFlag" column="delFlag"/>
<result property="updateDate" column="updateDate"/>
</resultMap>

<select id="selectUserByLoginName" resultMap="UserResult">
<![CDATA[
select * from user_info ui where ui.loginName = #loginName# and ui.delFlag=0
]]>
</select>

</sqlMap>


文件位置:

/hx/src/applicationContext.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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
default-autowire="byType">

<context:annotation-config />
<context:component-scan base-package="com.hx.*" />

<bean id="propertyConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<property name="driverClassName">
<value>${jdbc.driverClassName}</value>
</property>

<property name="url">
<value>${jdbc.url}</value>
</property>

<property name="username">
<value>${jdbc.username}</value>
</property>

<property name="password">
<value>${jdbc.password}</value>
</property>
</bean>

<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>classpath:SqlMapConfig.xml</value>
</property>

<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>

<bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</property>
</bean>



</beans>


文件位置:
/hx/src/SqlMapConfig.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<settings
cacheModelsEnabled="true"
enhancementEnabled="true"
lazyLoadingEnabled="true"
errorTracingEnabled="true"
maxRequests="32"
maxSessions="10"
maxTransactions="5"
useStatementNamespaces="false"
/>

<sqlMap resource="sqlmap/User.xml"/>

</sqlMapConfig>

文件位置:
/hx/src/com/hx/core/user/pojo/UserInfo.java

public class UserInfo extends BasePojo implements Serializable {
/**
*
*/
private static final long serialVersionUID = -289780747117628131L;

private int id;
private String fullName;
private String loginName;
private String password;
private String cellPhone;
private Date birthday;
private String position;
private String emailAddress;
private String location;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getLoginName() {
return loginName;
}
public void setLoginName(String loginName) {
this.loginName = loginName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getCellPhone() {
return cellPhone;
}
public void setCellPhone(String cellPhone) {
this.cellPhone = cellPhone;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}

}
...全文
362 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
7047bf472f32a076 2014-08-16
  • 打赏
  • 举报
回复
引用 9 楼 kutekute 的回复:
[quote=引用 8 楼 xh421041075 的回复:] [quote=引用 7 楼 kutekute 的回复:] [quote=引用 5 楼 youfeng445 的回复:] 找到问题了,多谢
什么问题啊[/quote] 怎么解决的啊 ????求解释[/quote] 我的是实体xml文件中出现错误了[/quote] sqlMapClient 这个注入到实现类里面去了吗 ?
kutekute 2014-07-16
  • 打赏
  • 举报
回复
引用 8 楼 xh421041075 的回复:
[quote=引用 7 楼 kutekute 的回复:] [quote=引用 5 楼 youfeng445 的回复:] 找到问题了,多谢
什么问题啊[/quote] 怎么解决的啊 ????求解释[/quote] 我的是实体xml文件中出现错误了
7047bf472f32a076 2014-07-10
  • 打赏
  • 举报
回复
引用 7 楼 kutekute 的回复:
[quote=引用 5 楼 youfeng445 的回复:] 找到问题了,多谢
什么问题啊[/quote] 怎么解决的啊 ????求解释
kutekute 2014-04-11
  • 打赏
  • 举报
回复
引用 5 楼 youfeng445 的回复:
找到问题了,多谢
什么问题啊
邪恶的小妖 2013-08-23
  • 打赏
  • 举报
回复
啥问题,到底是咋回事?
youfeng445 2013-07-07
  • 打赏
  • 举报
回复
找到问题了,多谢
小康师傅 2013-07-07
  • 打赏
  • 举报
回复
在applicationContext.xml中没有配置dao,导致无法加载dao相关的配置信息,可以参考一下这篇blog:http://blog.csdn.net/daryl715/article/details/1760793
youfeng445 2013-07-07
  • 打赏
  • 举报
回复
引用 2 楼 feier00 的回复:
sqlMapClient没被注入。

<bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
 
        <property name="driverClassName">
            <value>${jdbc.driverClassName}</value>
        </property>
 
        <property name="url">
            <value>${jdbc.url}</value>
        </property>
 
        <property name="username">
            <value>${jdbc.username}</value>
        </property>
 
        <property name="password">
            <value>${jdbc.password}</value>
        </property>
    </bean>
 
    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
        <property name="configLocation">
            <value>classpath:SqlMapConfig.xml</value>
        </property>
 
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
    </bean>
 
    <bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
        <property name="sqlMapClient">
            <ref bean="sqlMapClient" />
        </property>
    </bean>
但是配置文件中已经注入了
跳蚤图 2013-07-07
  • 打赏
  • 举报
回复
sqlMapClient没被注入。
meisei81 2013-07-07
  • 打赏
  • 举报
回复
http://download.csdn.net/detail/ludengji/4942907 参照这个资源去部署看看

81,122

社区成员

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

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