Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java EE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 BeanFactory factory 这里哪错了?为什么?
wangyzyoga





发贴: 8
积分: 0
于 2008-04-02 20:52 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
个位大侠来看看这段代码错误在哪?如何改正?
这是程序代码:
package test;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.RowCountCallbackHandler;

public class Test {
public static void main(String[] args){
Resource resource = new ClassPathResource("myspring.xml");
BeanFactory factory = new XmlBeanFactory(resource); //这里好像有错 按照提示
JdbcTemplate jt = (JdbcTemplate) factory.getBean("dbtest");
jt.execute(SqlStatement.createSql);
jt.execute(SqlStatement.insertData1);
jt.execute(SqlStatement.insertData2);
jt.execute(SqlStatement.insertData3);
RowCountCallbackHandler rcch = new RowCountCallbackHandler();
jt.query(SqlStatement.selectSql,rcch);
System.out.println("结果集中的列数量:" + rcch.getColumnCount());
System.out.println("结果集中的行数量:" + rcch.getRowCount());
System.out.println("结果集中的结果: ");
String[] str = rcch.getColumnNames();
for (int i = 0;i<str.length;i++){
System.out.print(str[i] + " ");
}
final ArrayList list = new ArrayList();
jt.query(SqlStatement.selectSql,new RowCallbackHandler(){
public void processRow(ResultSet rs) throws SQLException {
SpringtoResultSetInfo sri = new SpringtoResultSetInfo();
sri.setId(rs.getInt(1));
sri.setTemplatename(rs.getString(2));
list.add(sri);
}
}
);
for(int i=0;i <list.size();i++) {
SpringtoResultSetInfo sri = (SpringtoResultSetInfo)list.getLight Bulb;
System.out.println("\n" + " " + sri.getId());
System.out.print( " " + sri.getTemplatename());
}
System.out.println( "\n完成 ");
}
}
提示信息:
2008-4-2 20:49:58 org.springframework.core.CollectionFactory <clinit>
信息: JDK 1.4+ collections available
2008-4-2 20:49:58 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [myspring.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Line 14 in XML document from class path resource [myspring.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Attribute "destory-method" must be declared for element type "bean".
org.xml.sax.SAXParseException: Attribute "destory-method" must be declared for element type "bean".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:236)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:172)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:382)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:316)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.addDTDDefaultAttrsAndValidate(XMLDTDValidator.java:1306)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(XMLDTDValidator.java:1971)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:795)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:878)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1693)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:250)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:292)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:222)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:173)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:148)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:73)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:61)
at test.Test.main(Test.java:17)



作者 Re:BeanFactory factory 这里哪错了?为什么? [Re:wangyzyoga]
mazalet

如果英俊是一种罪,那

CJSDN高级会员


发贴: 430
积分: 60
于 2008-04-03 08:48 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
不是说的很明白吗?

   Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Line 14 in XML document from class path resource [myspring.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Attribute "destory-method" must be declared for element type "bean".
org.xml.sax.SAXParseException: Attribute "destory-method" must be declared for element type "bean".



如果你更热爱金钱而非自由,更习惯于被奴役的安宁而畏惧令人充满活力的争取自由的抗争,那么,请你静静地走开。我们不会乞求你的建议或是帮助。伏下身去讨好那喂养你的人吧。但愿身上的锁链不会给你造成太多的痛苦,但愿未来的人们不会记起你曾经是我们的国人。”
---------
作者 Re:BeanFactory factory 这里哪错了?为什么? [Re:wangyzyoga]
wangyzyoga





发贴: 8
积分: 0
于 2008-04-03 15:43 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我也知道那里是说错误的 可是关键是怎么改正?谢谢!!!


作者 Re:BeanFactory factory 这里哪错了?为什么? [Re:wangyzyoga]
JiafanZhou



版主


发贴: 736
积分: 61
于 2008-04-04 17:43 user profilesend a private message to usersend email to JiafanZhousearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
mazalet has pointed out that this is quite an obvious mistake that you should find out yourself how to fix. However I want to given you some hints here.

Before getting answers from us, look at this error again and think about it twice. If you still cannot figure out why, then go to my following sections.

- The error log mentioned "myspring.xml" is invalid, so all of the first, check to see if this file is in your project classpath.

- Check to see if this file is corrupted or have any funny characters.

- The error log also mentioned "destory-method" must be declared for element type "bean", think about why "destroy-method must be declared? If you still cannot figure out why, paste the "myspring.xml" file here.

- Think about using application context instead of bean factory. This is recommended by the Spring Framework.

Regards,
Jiafan



When I was a kid I used to pray every night for a new bike. Then I realized that The Lord doesn't work that way, so I stole one and asked him to forgive me.

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923