0

HDIV リファレンスに従って、Spring MVC アプリケーションにインストールしています。

すべてを実行しましたが、アプリケーションを実行すると、次の例外が発生しました。

Out 27, 2014 3:13:23 PM org.apache.catalina.core.StandardContext listenerStart
GRAVE: Exception sending context initialized event to listener instance of class org.hdiv.listener.InitListener
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.hdiv.config.HDIVConfig] is defined
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:319)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:985)

クラス HDIVConfig の springContext.xml に Bean を追加しようとしましたが、うまくいきませんでした。

他に何をする必要がありますか?

更新: web.xml:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

    <context-param>
        <param-name>spring.profiles.default</param-name>
        <param-value>producao</param-value>
    </context-param>

    <!--
     O Servlet abaixo eh a configuracao do SPRING-MVC e especificacao de onde encontrar o
     .xml que define o Application Context (quais classes sao o que etc.) do Spring
    -->
    <servlet>
        <servlet-name>Spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/springContext.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- Mapeia todas as requisicoes a esta aplicacao para o servlet definido anteriormente. -->
    <servlet-mapping>
        <servlet-name>Spring</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Configura a pagina que deve ser exibida quando algum caminho/URL nao mapeado for acessado. -->
    <error-page>
        <error-code>404</error-code>
        <location>/erro/404</location>
    </error-page>

    <filter>
        <filter-name>EncodingFilter</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>EncodingFilter</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>


    <!-- HDIV Validator Filter -->
    <listener>
        <listener-class>org.hdiv.listener.InitListener</listener-class>
    </listener>

    <filter>
        <filter-name>ValidatorFilter</filter-name>
        <filter-class>org.hdiv.filter.ValidatorFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>ValidatorFilter</filter-name>
        <!-- Spring MVC Servlet name-->
        <servlet-name>Spring</servlet-name>
    </filter-mapping>

</web-app>

そして、これが springContext.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:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:task="http://www.springframework.org/schema/task"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-4.0.xsd
                        http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
                        http://www.springframework.org/schema/task
                        http://www.springframework.org/schema/task/spring-task-4.0.xsd">

    <context:component-scan base-package="br.myapp"/>

    <context:annotation-config/>

    <mvc:annotation-driven>
    </mvc:annotation-driven>
    <mvc:resources mapping="/static/**" location="/static/" />
    <bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
        <property name="resourceLoaderPath" value="/WEB-INF/views/"/>
        <property name="velocityProperties">
            <props>
                <prop key="input.encoding">UTF-8</prop>
                <prop key="output.encoding">UTF-8</prop>
            </props>
        </property>
    </bean>
    <!-- #Velocity -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
        <property name="viewClass" value="br.myapp.componentes.view.velocity.PortalVelocityLayoutToolboxView" />
        <property name="cache" value="true" />
        <property name="prefix" value="" />
        <property name="suffix" value=".vm" />
        <property name="layoutUrl" value="layout/layout.vm" />

        <property name="contentType" value="text/html;charset=UTF-8" />
    </bean>

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

    <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
        <property name="defaultLocale" value="pt_BR"/>
    </bean>

    <mvc:interceptors>
        <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
            <property name="paramName" value="lang" />
        </bean>
    </mvc:interceptors>

    <task:annotation-driven executor="myExecutor" scheduler="myScheduler"/>
    <task:executor id="myExecutor" pool-size="1"/>
    <task:scheduler id="myScheduler" pool-size="2"/>

    <bean id="appConfigProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:application.properties" />
    </bean>

    <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>

    <jee:jndi-lookup id="Olimpiadas2016DataSource" jndi-name="java:/comp/env/jdbc/Olimpiadas2016DataSource"
        expected-type="javax.sql.DataSource" />

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="Olimpiadas2016DataSource"/>
        <property name="persistenceUnitName" value="Olimpiadas2016PersistenceUnit" />
    </bean>

    <tx:annotation-driven/>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <bean id="multipartResolver" class="org.hdiv.web.multipart.HdivCommonsMultipartResolver">
        <property name="maxUploadSize" value="100000" />
    </bean>
</beans>
4

1 に答える 1

5

hdiv:configspringContext.xml ファイルに構成がありません。以下の構成を xml に追加します。

<hdiv:config errorPage="/error.jsp">
    <hdiv:startPages>/,/attacks/.*</hdiv:startPages>
</hdiv:config> 

また、xml にスキーマを追加することを忘れないでください。

xmlns:hdiv="http://www.hdiv.org/schema/hdiv" 
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
                           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
                           http://www.hdiv.org/schema/hdiv http://www.hdiv.org/schema/hdiv/hdiv.xsd"

こちらがそのリファレンスです。詳細については、番号 3 と 4 を確認してください。

于 2014-10-27T17:42:13.237 に答える