使用 Spring Hibernate 的问题

发布于 12-11 03:51 字数 510 浏览 0 评论 0原文

我使用 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 文件。

I've been using Spring JDBC with great success but I am having alot of trouble with this project. I'll post the code links here(it's just a small and silly project to test if I can get it up and running so that I can use Hibernate in the future):

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

main-file: http://codepaste.net/iks1cp

I get tons of errors such as

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

and I haven't created a.out.xml file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

噩梦成真你也成魔2024-12-18 03:51:24

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

cvc-complex-type.2.3:元素“beans”不能具有字符 [children],因为该类型的内容类型是仅限元素的。

在一个或多个 声明之间似乎存在一些奇怪的字符。您是否从其他地方复制了此文本?

删除 定义之间的所有空格和换行符,并将它们放回编辑器中。

更新
复印&将您提供的代码粘贴中的文本粘贴到记事本++中,并将字符集设置为UTF-8,在空行中显示这些字符:xA0。这是   的标准 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>

This error is due to incorrect parsing of the xml file.
Using Eclipse to validate it gives the error:

cvc-complex-type.2.3: Element 'beans' cannot have character [children], because the type's content type is element-only.

There appears to be some strange character in between one or many of those <bean> declarations. Have you copied this text from somewhere else?

Remove all spaces and newline characters between <bean> definitions and put them back with your editor.

UPDATE
Copying & pasting into notepad++ the text in the codepaste you provided, and setting the charset to UTF-8 showed these characters in the blank lines: xA0. This is the standard Unicode translation for  . This is likely to be the cause of this problem.

This validates ok for me:

<?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>
清晨说晚安2024-12-18 03:51:24

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

If you are in linux, use cat -v file-name.xml to detect special "invisible" characters like 'M-BM-' in your xml file

一口甜2024-12-18 03:51:24

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

ctrl+shift+F

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

Sometimes there are hidden characters in dependencies or some bean definitions, which you copy from some tutorial's website. best way to find out those hidden characters do a `

ctrl + shift + F

this will format your document and you can see that hidden character in between some tag
`

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文