1

私は単純なアプリケーションを持っていますが<mvc:annotation-driven />、サーブレットに追加しようとすると、次のエラーが発生します:

[09/07/12 12:09:45:703 EDT] 00000053 DispatcherSer E org.springframework.web.servlet.FrameworkServlet initServletBean Context initialization failed
                                 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0': Invocation of init method failed; nested exception is java.lang.IllegalMonitorStateException

[09/07/12 12:09:45:718 EDT] 00000053 servlet       E com.ibm.ws.webcontainer.servlet.ServletWrapper init SRVE0100E: Uncaught init() exception created by servlet cm-dispatcher in application CM_ContractMaintenance: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0': Invocation of init method failed; nested exception is java.lang.IllegalMonitorStateException

私のディスパッチャサーブレット:

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

    <!-- Scans the classpath of this application for @Components to deploy as beans -->
    <context:component-scan base-package="ca.gc.ic.cipo.cm.web" />    

    <!-- Saves a locale change using a cookie -->
    <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" />

    <!-- Application Message Bundle -->
    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="messages" />
        <property name="cacheSeconds" value="0" />
    </bean>

    <!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean> 

    <!-- Configures the @Controller programming model -->
    <mvc:annotation-driven />

</beans>

私の Web.XML

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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" version="2.5">

    <display-name>Contract Maintenance Web Application</display-name>

    <!-- Reads request input using UTF-8 encoding -->
    <filter>
        <filter-name>characterEncodingFilter</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>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- Handles all requests into the application -->
    <servlet>
        <servlet-name>cm-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/cm-dispatcher-servlet.xml
            </param-value>          
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>cm-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <!-- Spring Security --> 
<!--    <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>   
 -->

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

    <error-page>
        <error-code>404</error-code>
        <location>/WEB-INF/jsp/404.jsp</location>
    </error-page>

    <error-page>
        <exception-type>java.lang.Exception
        </exception-type>
        <location>/WEB-INF/jsp/404.jsp</location>
    </error-page>

    <!-- Datasource definition section -->
    <resource-ref>
        <description>The datasource reference for the Contract Maintenance
            Application. There will be a corresponding reference bound in
            'ibm-web-bnd.xml'.</description>
        <res-ref-name>CMDatasource</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>

</web-app>

私のpom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>cipo-parent</artifactId>
    <groupId>ca.gc.ic.cipo</groupId>
    <version>1.1</version>
  </parent>

  <groupId>ca.gc.ic.cipo.cm</groupId>
  <artifactId>cm-webapp</artifactId>
  <packaging>war</packaging>
  <version>1.1</version>
  <name>cm-webapp Maven Webapp</name>
  <url>http://maven.apache.org</url>

  <properties>
    <spring.version>3.1.1.RELEASE</spring.version>
    <spring.security.version>3.1.0.RELEASE</spring.security.version>

  </properties>

   <dependencies>
    <dependency>
        <groupId>ca.gc.ic.cipo.cm</groupId>
        <artifactId>cm-product-core</artifactId>
        <version>1.1</version>
    </dependency>          
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
    </dependency>        
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>6.0</version>
    </dependency>
    <dependency>
      <groupId>commons-configuration</groupId>
      <artifactId>commons-configuration</artifactId>
      <version>1.6</version>      
    </dependency>
      <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>1.4</version>      
    </dependency>
    <dependency>
      <groupId>commons-lang</groupId>
      <artifactId>commons-lang</artifactId>
      <version>2.5</version>      
    </dependency>
    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>1.1.1</version>      
    </dependency>

    <!-- Spring 3 dependencies -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <!--  Reinject dependencies due to Spring Security -->
    <!--  Spring Aspect Oriented Programming (AOP) Framework --> 
    <dependency>         
        <groupId>org.springframework</groupId>         
        <artifactId>spring-aop</artifactId>         
        <version>${spring.version}</version>     
    </dependency>

    <!-- Spring Core Framework -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <!-- Spring Application Context --> 
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <!-- Spring JDBC  --> 
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <!--  Spring Bean Factory and JavaBeans utilities -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <!-- Spring Core Framework -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <!--  Spring Security -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>${spring.security.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>${spring.security.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.3.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.4</version>
        <scope>runtime</scope>
    </dependency>
    <dependency> 
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <version>1.6.1</version>
    </dependency>
  </dependencies>

  <build>
    <finalName>cm-webapp</finalName>
  </build>
</project>

ヘルプ!!

4

2 に答える 2

1

Websphere でこのエラーが発生していることがわかります。これは、Websphere によって提供される JSR 303 バリデーターの実装が、依存関係にある休止状態のものと競合している可能性があるためだと推測しています。2つのことを試していただけますか -

1 つは、ランタイムのデプロイメントで hibernate-validator jar を削除することです。これにより、バリデーターが IBM によって提供されたものを使用するように強制される場合があります。

最初の方法が機能しない場合の 2 番目の方法は、休止状態バリデーターの使用を強制することです。次の方法で実行できます。

<bean name="handlerAdapter" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
    <property name="webBindingInitializer">
        <bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">

            <property name="validator">
                <bean class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
                    <property name="providerClass" value="org.hibernate.validator.HibernateValidator"></property>
                </bean>
            </property>
        </bean>
    </property>
    <property name="messageConverters">
        <list>
            <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"></bean>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter"></bean>
            <bean class="org.springframework.http.converter.ResourceHttpMessageConverter"></bean>
            <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"></bean>
            <bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter"></bean>
            <bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"></bean>
            <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"></bean>
        </list>
    </property>
</bean>
于 2012-07-10T12:55:55.347 に答える
0

仮定して :

<context:component-scan base-package="ca.gc.ic.cipo.cm.web" />

コントローラがある場所<mvc:annotation-driven />です。コマンドをその直前に配置してみてください。

それは私が春3.0.5で行うことです。3.1でも同じだと思います。

また、私は通常、すべてのlocalresolver、viewresolversなどの後に最後にコントローラーを配置することにも注意してください<context:component-scan...春の魔法が多すぎると、アプリケーション全体の初期化が台無しになることがあります。

于 2012-07-10T12:37:27.633 に答える