2016-04-21 2 views
0

У меня ошибка в моем servlet-context.xml. Он говорит, что он может найти ниже классы, но они действительно существуют в папке projecct.java.lang.ClassNotFoundException: com.springhibernatemvc.dao.PersonDAOImpl

<beans:bean id="personDAO" class="com.springhibernatemvc.dao.PersonDAOImpl"> 
     <beans:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" /> 
    </beans:bean> 
    <beans:bean id="personService" class="com.springbibernate.services.PersonServiceImpl"> 
     <beans:property name="personDAO" ref="personDAO"></beans:property> 
    </beans:bean> 

Он говорит, что этот класс не найден

- Class 'com.springbibernate.services.PersonServiceImpl' 

Мой файл сервлет-контекст также определен в моем файле web.xml

<servlet> 
     <servlet-name>appServlet</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

Я добавление сервлета-контекст .xml в корневую папку моего веб-приложения, но все еще существует ошибка.

Полная StackTrace

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Invocation of init method failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.springhibernatemvc.dao.PersonDAOImpl] for bean with name 'personDAO' defined in ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]; nested exception is java.lang.ClassNotFoundException: com.springhibernatemvc.dao.PersonDAOImpl 
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.springhibernatemvc.dao.PersonDAOImpl] for bean with name 'personDAO' defined in ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]; nested exception is java.lang.ClassNotFoundException: com.springhibernatemvc.dao.PersonDAOImpl 

Что может быть не так?

ответ

1

из Java Docs

Брошенный, когда приложение пытается загрузить в класс через его имя строки с помощью:

  • Метод forName в классе Class.
  • Метод findSystemClass в классе ClassLoader.
  • Метод loadClass класса ClassLoader.

, но определение класса с указанным именем не найдено.

Проблема здесь не в файле servlet-context.xml, а в том, что в нем определены компоненты. убедитесь, что полные имена пустых кланов верны, и соответствующие файлы классов присутствуют в WEB-INF или в некоторой библиотеке под этим.

С первого высокого уровня посмотреть, кажется, что вы определяете боб с классом, как «com.spring б ibernate.services.PersonServiceImpl»

где правильное название, кажется, «com.spring ч ibernate.services.PersonServiceImpl»

Так содержание XML должно быть как:

<beans:bean id="personDAO" class="com.springhibernatemvc.dao.PersonDAOImpl"> 
     <beans:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" /> 
    </beans:bean> 
    <beans:bean id="personService" class="com.springhibernate.services.PersonServiceImpl"> 
     <beans:property name="personDAO" ref="personDAO"></beans:property> 
    </beans:bean> 
+0

Я фактически скорректированной, но это не сработало – Blaze

+0

классы присутствуют в WEB-INF папку – Blaze

+0

Confirm это то, что вы ищете WEB-INF/classes/com/springhibernatemvc/dao/PersonDAOImpl.class, а также вы можете вставить последнее сообщение об ошибке. –

0

сделать запись о приведенные ниже теги в файле XML пружинного контекста:

<context:annotation-config /> 
<context:component-scan base-package="com.springhibernate.services, com.springhibernatemvc.dao" /> 

если вы получаете java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener затем следуйте приведенным ниже ссылке:

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

Смежные вопросы