[英]Problems using Spring Hibernate
I've been using Spring JDBC with great success but I am having alot of trouble with this project. 我一直在使用Spring JDBC取得了巨大的成功,但我在这个项目上遇到了很多麻烦。 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):
我将在这里发布代码链接(这只是一个小而愚蠢的项目来测试我是否可以启动并运行以便将来可以使用Hibernate):
xml-file: http://codepaste.net/uw19zc xml-file: http : //codepaste.net/uw19zc
main-file: http://codepaste.net/iks1cp 主文件: 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. 我还没有创建a.out.xml文件。
This error is due to incorrect parsing of the xml file. 此错误是由于xml文件的解析不正确造成的。 Using Eclipse to validate it gives the error:
使用Eclipse验证它会产生错误:
cvc-complex-type.2.3: Element 'beans' cannot have character [children], because the type's content type is element-only.
cvc-complex-type.2.3:元素'beans'不能有字符[children],因为类型的内容类型只是元素。
There appears to be some strange character in between one or many of those <bean>
declarations. 在这些
<bean>
声明中的一个或多个之间似乎存在一些奇怪的特征。 Have you copied this text from somewhere else? 你是否从其他地方复制过这段文字?
Remove all spaces and newline characters between <bean>
definitions and put them back with your editor. 删除
<bean>
定义之间的所有空格和换行符,并将它们与编辑器一起放回。
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 . 更新复制并粘贴到记事本++中您提供的代码膏中的文本,并将字符集设置为UTF-8在空白行中显示这些字符: xA0 。 This is the standard Unicode translation for
这是
的标准Unicode翻译 . 。 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>
如果您在linux中,请使用cat -v file-name.xml
在xml文件中检测特殊的“不可见”字符,如“M-BM-”
Sometimes there are hidden characters in dependencies or some bean definitions, which you copy from some tutorial's website. 有时在依赖项或某些bean定义中存在隐藏的字符,您可以从某些教程的网站复制这些字符。 best way to find out those hidden characters do a `
找出那些隐藏字符的最佳方法是做一个`
ctrl + shift + F
ctrl + shift + F.
this will format your document and you can see that hidden character in between some tag ` 这将格式化您的文档,您可以在某个标记`之间看到隐藏的字符
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.