Topic: 请教Spring错误问题

  Print this page

1.请教Spring错误问题 Copy to clipboard
Posted by: Platformer
Posted on: 2006-05-22 09:57

这是我写的测试代码:
package com.towset.sshdlib.util;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.towset.sshdlib.business.IEleBookService;
import com.towset.sshdlib.business.service.EleBookImp;
import com.towset.sshdlib.business.IBookMarkService;
import com.towset.sshdlib.business.service.BookMarkImp;
import com.towset.sshdlib.business.IBorrowInfoService;
import com.towset.sshdlib.business.service.BorrowInfoImp;

import com.towset.sshdlib.model.BookConern;
import com.towset.sshdlib.model.BookMark;
import com.towset.sshdlib.model.BorrowBookInfo;
import com.towset.sshdlib.model.ElectionBook;
import com.towset.sshdlib.model.UserInfo;

public class Test {
IEleBookService service;
  EleBookImp ebi;
//  IBookMarkService ibmark;
//  BookMarkImp bmark;
//  IBorrowInfoService ibinfo;
//  BorrowInfoImp binfo;
  
  ElectionBook eb = new ElectionBook();
  BookConern bc = new BookConern();
  UserInfo ui=new UserInfo();
  BookMark bm=new BookMark();
  BorrowBookInfo bbi=new BorrowBookInfo();
  
  
  public void save(){
    ApplicationContext context =
     new ClassPathXmlApplicationContext(new String[]{"daoBean.xml","serviceBean.xml"});    
    
//    ApplicationContext context=
//      new ClassPathXmlApplicationContext("bean.xml");
    
//    ebi=(EleBookImp)context.getBean("ieleBookService");
    
    service=(IEleBookService)context.getBean("ieleBookService");
    
    
//    Session se = HibernateUtil.currentSession();
//    Transaction tx = se.beginTransaction();
    
    bc.setCname("renyou");
    bc.setCisbn("345");
    bc.setCtel("1357");
    bc.setCaddress("shanghai");
    bc.setCremark("haode");
    
   eb.setEthesis("zero");
    eb.setEresponsible("wang");
   eb.setEisbn("12423");
    eb.setEurl("d:/TowSet");
   eb.setEsort("kexue");
    eb.setEclegree(2);
    eb.setEremark("chenggong");
    eb.setBconern(bc);
    
    System.out.println("bao");
//    se.save(eb);
//    tx.commit();
//    HibernateUtil.closeSession();
      
//    ebi.createObject(eb);
    service.createObject(eb);
  }
  
  public ElectionBook getEleBookByIsbn(Long isbn){
    ApplicationContext context= new ClassPathXmlApplicationContext(new String[]{"daoBean.xml","serviceBean.xml"});
    ebi=(EleBookImp)context.getBean("eleBookService");
    return eb=ebi.findById(isbn);
  }
  
  public void deleteElebook(String isbn){
    ApplicationContext context= new ClassPathXmlApplicationContext(new String[]{"daoBean.xml","serviceBean.xml"});
    ebi=(EleBookImp)context.getBean("eleBookService");
    ebi.deleteObject(isbn);
  }
  
  public static void main(String[] args) {
    // TODO 自动生成方法存根
    Test te = new Test();
    te.save();

  }

}
----------------------------------------------提示以下错误信息------------------------------
[web] WARN [main] Configurator.configure(126) | No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/D:/SSHdlib1/WebRoot/WEB-INF/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
bao
Exception in thread "main" java.lang.NullPointerException
  at com.towset.sshdlib.business.service.BaseService.createObject(BaseService.java:22)
  at com.towset.sshdlib.business.service.BaseService$$FastClassByCGLIB$$f6752a3d.invoke(<generated>Wink
  at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
  at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:698)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
  at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
  at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:643)
  at com.towset.sshdlib.business.service.EleBookImp$$EnhancerByCGLIB$$acc686d5.createObject(<generated>Wink
  at com.towset.sshdlib.util.Test.save(Test.java:72)
  at com.towset.sshdlib.util.Test.main(Test.java:90)
我找了好长时间但还是找不到,希望各位大大帮帮小弟!~

2.Re:请教Spring错误问题 [Re: Platformer] Copy to clipboard
Posted by: Davis129
Posted on: 2006-05-30 10:50

你还在吗 是不是main函数里的 Test te = new Test();这句有问题
是不是在Test class里可以加个Test()构造函数
我是新手 如果我的理解有问题 希望告诉我 谢谢!


   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