2011-06-04 230 views
0

我想互动与春天休眠在我的GWT项目,下面是我的代码无法实例化bean类

public class MyWebServiceImpl extends RemoteServiceServlet implements 
    MyWebService { 

public void myfirstmethod() { 
    // TODO Auto-generated method stub 

} 

public String signIn(String userid, String password) { 
    ApplicationContext ctx = new ClassPathXmlApplicationContext(
    "applicationContext.xml"); 
    MySQLRdbHelper rdbHelper = (MySQLRdbHelper) ctx.getBean("ManagerJobs"); 
    **//THIS IS THE POINT WHERE IT THROWS THE EXCEPTION** 

    return rdbHelper.getAuthentication(userid, password); 
} 

}

 public class MySQLRdbHelper { 


private Session session; 
private SessionFactory sessionFactory; 
    /* FOR COUNT QUERY 
    * session.createCriteria(RuleSet .class) 
    .setProjection(Projections.projectionList() 
      .add(Projections.rowCount())) 
    .add(Subqueries.geAll("entry_id", bolgsEntries)) 
    .list(); 
*/ 
public void setSessionFactory(SessionFactory sessionFactory) { 
    this.sessionFactory = sessionFactory; 
    } 

public String getAuthentication(String userid, String password) 
{ 
    //Some detals like credit card are commented in the class 
    User users = null; 
    session = sessionFactory.openSession(); 
    Criteria crit = session.createCriteria(User.class); 
    crit.add(Restrictions.eq("userName", userid)); 
    crit.add(Restrictions.eq("password", password)); 

    List rsList = crit.list(); 
    for(Iterator it=rsList.iterator(); 

    it.hasNext(); 
    ) 
    { 
     users = (User)it.next(); 
     System.out.println(users.getUserName()); 
    } 
    session.close(); 
    return users.getUserName(); 
} 

}

  APPLICATIONCONTEXT.XML 
     <?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-2.0.xsd" 
    default-lazy-init="true"> 

     <!-- Datasource for database connection --> 
     <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
     <property name="driverClassName" value="com.mysql.jdbc.Driver" /> 
     <property name="url" 
     value="jdbc:mysql://localhost:3306/patients" /> 
     <property name="username" value="root" /> 
     <property name="password" value="" /> 
     </bean> 

     <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
     <property name="dataSource" ref="dataSource" /> 
     <property name="annotatedClasses"> 
     <list> 
<value>com.Patient.shared.User</value> 

     </list> 
     </property> 
     </bean> 
     <bean id ="ManagerJobs" class= "patient.persistence.MySQLRdbHelper"> 
     <property name="sessionFactory" ref="sessionFactory" /> 
    </bean> 

这是例外

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ManagerJobs' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.hibernate.cfg.AnnotationConfiguration]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory 

回答

1

你缺少你的classpath SLF4J通过

java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory 

指示得到它,并添加到应用程序。

+0

,谢谢,我已经添加了SLF4J的API-1.3.1.jar和SLF4J-log4j12-1.5.6.jar,但问题仍然存在任何建议感谢 – junaidp 2011-06-04 04:48:30

+0

@junaidp用相同的加SLF4J罐子版本。同样的问题意味着你看到相同的'java.lang.NoClassDefFoundError:org/slf4j/LoggerFactory'吗? – 2011-06-04 05:34:04

+0

@ junaidp你还把你的罐子放在哪里?我记得在托管模式下,我必须将slf4j jar放入WEB-INF/lib中。他们没有从普通的课程路径中获得。 – 2011-06-04 05:38:32

-2
This is my Controller file.......... 
@Controller 
public class AutoCompleteController { 
    //@Resource(name = "blCatalogService") 
    //protected CatalogService catalogService; 
     @RequestMapping(value = "/AutoComplete", produces = "application/json") 
     [email protected]<Product>AutoComplete(HttpServletRequest request, 
      HttpServletResponse response,Model model, CatalogService catalogService){ 
    List <Product> list=new ArrayList<Product>(); 
    String autostr=request.getParameter("autocomp"); 
    System.out.println("AutoComplete Controller" + autostr); 
    try { 
     //database query searchString; 
     CatalogService catalogService1=new CatalogServiceImpl(); 
     list = catalogService1.findProductsByName(autostr); 
     System.out.println("Result:"+list); 

    } 
     catch (Exception e) { 
     System.out.println("Error inside AutoComplete Controller"); 
      e.printStackTrace(); 
     } 
     return list; 

    } 

    } 
    This is my js File 


function ajaxAutoComplete(a) 
{ 

    var querystring = "&isAjax=1&autocomp="+jQuery("#autocomp").val(); 
    jQuery.ajax({ 
     url: a, 
     dataType: "json", 
     type: "post",`enter code here` 
     data: querystring, 
     success: function (data){} 
    }); 
} 
that the time it will produced that error. 
500 Could not instantiate bean class 
org.broadleafcommerce.core.catalog.service.CatalogService]: 
相关问题