繁体   English   中英

使用Spring Hibernate的问题

[英]Problems using Spring Hibernate

我一直在使用Spring JDBC取得了巨大的成功,但我在这个项目上遇到了很多麻烦。 我将在这里发布代码链接(这只是一个小而愚蠢的项目来测试我是否可以启动并运行以便将来可以使用Hibernate):

xml-file: http//codepaste.net/uw19zc

主文件: http//codepaste.net/iks1cp

我遇到了很多错误

[Fatal Error] bean2.out.xml:1:1: Premature end of file.
13:21:39,471 FATAL [main] Main  - getAssociatedStylesheets failed

我还没有创建a.out.xml文件。

此错误是由于xml文件的解析不正确造成的。 使用Eclipse验证它会产生错误:

cvc-complex-type.2.3:元素'beans'不能有字符[children],因为类型的内容类型只是元素。

在这些<bean>声明中的一个或多个之间似乎存在一些奇怪的特征。 你是否从其他地方复制过这段文字?

删除<bean>定义之间的所有空格和换行符,并将它们与编辑器一起放回。

更新复制并粘贴到记事本++中您提供的代码膏中的文本,并将字符集设置为UTF-8在空白行中显示这些字符: xA0 这是&nbsp;的标准Unicode翻译 这可能是导致此问题的原因。

这对我来说有效:

<?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="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/HibernateDB" />
        <property name="username" value="HibernateDB" />
        <property name="password" value="java" />
    </bean>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
        <property name="annotatedClasses">
            <list>
                <value>hdao.HibernateObject</value>
            </list>
        </property>
    </bean><bean id="springHibernateOperator" class="hdao.SpringHibernateOperatorImplementation">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
</beans>

如果您在linux中,请使用cat -v file-name.xml在xml文件中检测特殊的“不可见”字符,如“M-BM-”

有时在依赖项或某些bean定义中存在隐藏的字符,您可以从某些教程的网站复制这些字符。 找出那些隐藏字符的最佳方法是做一个`

ctrl + shift + F.

这将格式化您的文档,您可以在某个标记`之间看到隐藏的字符

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM