Spring配置文件下为什么老报这个java.lang.IllegalArgumentException:错误啊
Causedby:java.lang.IllegalArgumentException:Mappingdirectorylocation[ServletContextre...
Caused by: java.lang.IllegalArgumentException: Mapping directory location [ServletContext resource [/User.hbm.xml]] does not denote a directory
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:662)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 30 more
配置文件如下:
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/post?useUnicode=true&characterEncoding=utf-8</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>111111</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.jdbc.fetch_size">10</prop>
<prop key="hibernate.jdbc.batch_size">50</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>post.vo</value>
</list>
</property>
<property name="mappingDirectoryLocations">
<list>
<value>User.hbm.xml</value>
</list>
</property>
</bean>
<bean id="userDao" class="post.dao.achieve.UserDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="userDAO" class="post.action.UserAction">
<property name="userDAO">
<ref bean="userDao" />
</property>
</bean>
Hibernate配置:
<hibernate-mapping>
<class name="post.vo.User" table="USER" catalog="post">
<id name="id" column="ID" type="java.lang.Integer">
<generator class="increment">
</id>
<property name="uname" column="UNAME" type="java.lang.String" length="35" />
<property name="password" column="PASSWORD" type="java.lang.String" length="18" not-null="false" />
<property name="sex" column="SEX" type="java.lang.String" length="2" not-null="false" />
<property name="age" column="AGE" type="java.lang.Integer" not-null="false" />
<property name="nickName" coulmn="NICK_NAME" type="java.lang.String" length="20" not-null="false"/>
</class>
</hibernate-mapping>
请大侠们指点,谢了。
<property name="mappingDirectoryLocations">
这里的问题,当我把这里的mappingDirectoryLocations改成mappingResources时,错误就不在出现了,谢谢大家。所以我就结给第一个给我答复的人。 展开
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:662)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 30 more
配置文件如下:
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/post?useUnicode=true&characterEncoding=utf-8</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>111111</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.jdbc.fetch_size">10</prop>
<prop key="hibernate.jdbc.batch_size">50</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>post.vo</value>
</list>
</property>
<property name="mappingDirectoryLocations">
<list>
<value>User.hbm.xml</value>
</list>
</property>
</bean>
<bean id="userDao" class="post.dao.achieve.UserDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="userDAO" class="post.action.UserAction">
<property name="userDAO">
<ref bean="userDao" />
</property>
</bean>
Hibernate配置:
<hibernate-mapping>
<class name="post.vo.User" table="USER" catalog="post">
<id name="id" column="ID" type="java.lang.Integer">
<generator class="increment">
</id>
<property name="uname" column="UNAME" type="java.lang.String" length="35" />
<property name="password" column="PASSWORD" type="java.lang.String" length="18" not-null="false" />
<property name="sex" column="SEX" type="java.lang.String" length="2" not-null="false" />
<property name="age" column="AGE" type="java.lang.Integer" not-null="false" />
<property name="nickName" coulmn="NICK_NAME" type="java.lang.String" length="20" not-null="false"/>
</class>
</hibernate-mapping>
请大侠们指点,谢了。
<property name="mappingDirectoryLocations">
这里的问题,当我把这里的mappingDirectoryLocations改成mappingResources时,错误就不在出现了,谢谢大家。所以我就结给第一个给我答复的人。 展开
4个回答
展开全部
<bean id="userDAO" class="post.action.UserAction">
<property name="userDAO">
<ref bean="userDao" />
</property>
</bean>
你这配置的Action? 配置Action的时候不是用的
<bean name="Struts-config.xml里的action上下文路径:/path" class="post.action.UserAction">
<property name="userDAO">
<ref bean="userDao" />
</property>
</bean>
??????
<property name="userDAO">
<ref bean="userDao" />
</property>
</bean>
你这配置的Action? 配置Action的时候不是用的
<bean name="Struts-config.xml里的action上下文路径:/path" class="post.action.UserAction">
<property name="userDAO">
<ref bean="userDao" />
</property>
</bean>
??????
追问
还是不行,它主要提出的错误是那个 User.hbm.xml文件。就算我把那部分去掉,运行还是报这个User.hbm.xml文件的错误。
追答
那你的User.hbm.xml文件的路径是否写真确了?直接在src下的??
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
User.hbm.xml file location is incorrect, please check it . may be you configure the same as class path.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
看看hbm的路径是否正确
看看hbm里面对应pojo类的路径是不是正确
看看hbm里面对应pojo类的路径是不是正确
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询