2016-08-17 2 views
0

Я пытаюсь развернуть мое веб-приложение в tomcat 7 на внешней виртуальной машине Amazon EC2 на ubuntu, и я всегда получаю сообщение об ошибке. Я запускаю веб-приложение на своем компьютере, и оно работает.Развертывание веб-приложения в Tomcat 7 на Amazon EC2 на Ubuntu

Ошибка:

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener 
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.test.registration.dao.UserDAOImpl] for bean with name 'userDAOImpl' defined in file [/var/lib/tomcat7/webapps/ServerApp/WEB-INF/classes/com/test/registration/dao/com.test.regist$ 

Это мои основные XML-файлы:

web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 
    <!-- Описание корневого контейнера, разделяемого всеми сервлетами и фильтрами --> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      /WEB-INF/spring/root-context.xml 
     </param-value> 
    </context-param> 
    <!-- Создаёт контейнер Spring, разделяемый всеми сервлетами и фильтрами --> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 
    <!-- Базовый сервлет, обрабатывает все запросы к приложению --> 
    <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> 
    <servlet> 
     <servlet-name>DownloadServlet</servlet-name> 
     <servlet-class>com.test.servlets.DownloadServlet</servlet-class> 
    </servlet> 
    <servlet> 
     <servlet-name>UploadServlet</servlet-name> 
     <servlet-class>com.test.servlets.UploadServlet</servlet-class> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>appServlet</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 
    <servlet-mapping> 
     <servlet-name>DownloadServlet</servlet-name> 
     <url-pattern>/downloadservlet</url-pattern> 
    </servlet-mapping> 
    <servlet-mapping> 
     <servlet-name>UploadServlet</servlet-name> 
     <url-pattern>/uploadservlet</url-pattern> 
    </servlet-mapping> 

    <!-- Фильтр для перекодировки в utf8 --> 
    <filter> 
     <filter-name>charsetFilter</filter-name> 
     <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 
     <init-param> 
      <param-name>encoding</param-name> 
      <param-value>UTF-8</param-value> 
     </init-param> 
     <init-param> 
      <param-name>forceEncoding</param-name> 
      <param-value>true</param-value> 
     </init-param> 
    </filter> 
    <filter-mapping> 
     <filter-name>charsetFilter</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 
    <filter> 
     <filter-name>springSecurityFilterChain</filter-name> 
     <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
    </filter> 
    <filter-mapping> 
     <filter-name>springSecurityFilterChain</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 

    <welcome-file-list> 
     <welcome-file>/login.jsp</welcome-file> 
    </welcome-file-list> 
</web-app> 

корня context.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" xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" 
    xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:util="http://www.springframework.org/schema/util" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
     http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd 
     http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd 
     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> 

    <!-- Root Context: определяет ресурсы, доступные всему приложению, всем сервлетам --> 

    <!-- Включаем опцию использования конфигурационных аннотаций (@Annotation-based configuration)--> 
    <context:annotation-config /> 

    <!-- Определяем папки, в которых будем автоматически искать бины-компоненты (@Component, @Service) --> 
    <context:component-scan base-package="com.test.registration.dao"> 
     <context:include-filter expression="org.springframework.stereotype.Controller" 
      type="annotation" /> 
     </context:component-scan> 
    <context:component-scan base-package="com.test.registration.service"> 
     <context:include-filter expression="org.springframework.stereotype.Controller" 
      type="annotation" /> 
     </context:component-scan> 

    <!-- Файл с настройками ресурсов для работы с данными (Data Access Resources) --> 
    <import resource="data.xml" /> 

    <!-- Файл с настройками безопасности --> 
    <import resource="security.xml" /> 

</beans> 

data.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" xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" 
    xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:util="http://www.springframework.org/schema/util" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd 
     http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd 
     http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd 
     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> 

    <!-- Настраивает управление транзакциями с помощью аннотации @Transactional --> 
    <tx:annotation-driven transaction-manager="transactionManager" /> 

    <!-- Менеджер транзакций --> 
    <bean id="transactionManager" 
     class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
     <property name="sessionFactory" ref="sessionFactory" /> 
    </bean> 

    <bean id="messageSource" 
     class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
     <property name="basename" value="classpath:messages" /> 
     <property name="defaultEncoding" value="UTF-8" /> 
    </bean> 

    <!-- Настройки бина dataSource будем хранить в отдельном файле --> 
    <bean id="propertyConfigurer" 
     class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" 
     p:location="/WEB-INF/jdbc.properties" /> 

    <!-- Непосредственно бин dataSource --> 
    <bean id="dataSource" 
     class="org.springframework.jdbc.datasource.DriverManagerDataSource" 
     p:driverClassName="${jdbc.driverClassName}" 
     p:url="${jdbc.databaseurl}" 
     p:username="${jdbc.username}" 
     p:password="${jdbc.password}" /> 

    <!-- Настройки фабрики сессий Хибернейта --> 
    <bean id="sessionFactory" 
     class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 
     <property name="dataSource" ref="dataSource" /> 
     <property name="configLocation"> 
      <value>classpath:hibernate.cfg.xml</value> 
     </property> 
     <property name="configurationClass"> 
      <value>org.hibernate.cfg.AnnotationConfiguration</value> 
     </property> 
     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.show_sql">true</prop> 
       <prop key="hibernate.dialect">${jdbc.dialect}</prop> 
       <prop key="hibernate.connection.charSet">UTF-8</prop> 
      </props> 
     </property> 
    </bean> 
</beans> 

Я развертываю простую программу HelloWorld, и она работает. Моя весенняя версия 3.2.9RELEASE.

+0

У вас есть ссылка на 'userDAOImpl' где-то в вашем коде, но вы не включаете это в свое развертывание. Я думаю, ссылка ссылается на зависимость Spring bean, поскольку она явно не указана в вашей конфигурации Spring XML. –

+0

Благодарим вас за ответ. Я добавил строку: И это работает! –

ответ

0

Я добавил в data.xml строки:

<bean id="userDAOImpl" class="com.test.registration.dao.UserDAOImpl" /> 

Также я удалил все комментарии русских! И теперь это работает!

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