获取java.lang.IllegalArgumentException:初始化时,存储库接口不能为null?

时间:2022-11-20 20:51:42

I am trying to create spring mvc application and getting this exception

我正在尝试创建spring mvc应用程序并获得此异常

I get this error: http://pastebin.com/jypSeRPY

我收到此错误:http://pastebin.com/jypSeRPY

==============================================================

        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>
        <groupId>com.ceb</groupId>
        <artifactId>elastic_search</artifactId>
        <packaging>war</packaging>
        <version>0.0.1-SNAPSHOT</version>
        <name>elastic_search Maven Webapp</name>
        <url>http://maven.apache.org</url>




        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <java.version>1.8</java.version>
        </properties>
        <dependencies>

        <!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>2.5</version>
            </dependency>


            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
                <version>4.2.6.RELEASE</version>
            </dependency>

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>4.2.6.RELEASE</version>
            </dependency>

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
                <version>4.2.6.RELEASE</version>
            </dependency>

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
                <version>4.2.6.RELEASE</version>
            </dependency>


    <!--        <dependency> -->
    <!--     <groupId>org.springframework</groupId> -->
    <!--     <artifactId>spring-tx</artifactId> -->
    <!--     <version>4.2.6.RELEASE</version> -->
    <!-- </dependency> -->

            <!-- jstl -->
            <dependency>
                <groupId>jstl</groupId>
                <artifactId>jstl</artifactId>
                <version>1.2</version>
            </dependency>



            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-elasticsearch</artifactId>
                <version>1.3.4.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
            </dependency>

            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>3.8.1</version>
                <scope>test</scope>
            </dependency>

            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>2.3.1</version>
            </dependency>


        </dependencies>

        <build>
            <finalName>elastic_search</finalName>
        </build>
    </project>

        -------------------------------------------------------------

        web.xml 

    <?xml version="1.0" encoding="UTF-8"?>
    <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">
      <display-name>Elastic_Demo</display-name>
      <welcome-file-list>

        <welcome-file>/Pages/jsp/common/index.jsp</welcome-file>

      </welcome-file-list>

      <servlet>
            <servlet-name>mvc-dispatcher</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>

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

        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/applicationContext.xml</param-value>
        </context-param>

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

    </web-app>

            --------------------------------------------------------------


     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" xmlns:mvc="http://www.springframework.org/schema/mvc"      
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
           xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">

        <context:annotation-config/>
        <bean name="mainBean" class="com.elastic.repository.ElasticSearchRepository"/>

        <elasticsearch:repositories base-package="com.elastic.repository"/>
        <elasticsearch:repositories base-package="com.elastic.entity"/>

        <context:component-scan base-package="com.elastic" />

        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix">
                <value>/WEB-INF/pages/jsp/</value>
            </property>
            <property name="suffix">
                <value>.jsp</value>
            </property>
        </bean>


        <mvc:annotation-driven />

    </beans>

I am not able to figure out the exact Issue in this, can anyone help me with this?

我无法弄清楚这个问题,任何人都可以帮我解决这个问题吗?

1 个解决方案

#1


0  

        I got the solution for this 

        1) I have changed sequence of components scan in applicationContext.xml 
from 

    <elasticsearch:repositories base-package="com.elastic.repository"/>
    <elasticsearch:repositories base-package="com.elastic.entity"/>
    <context:component-scan base-package="com.elastic" />

    to 

    <context:component-scan base-package="com.elastic" />
    <elasticsearch:repositories base-package="com.elastic.repository" />
    <elasticsearch:repositories base-package="com.elastic.entity" />


Base package should come first .

#1


0  

        I got the solution for this 

        1) I have changed sequence of components scan in applicationContext.xml 
from 

    <elasticsearch:repositories base-package="com.elastic.repository"/>
    <elasticsearch:repositories base-package="com.elastic.entity"/>
    <context:component-scan base-package="com.elastic" />

    to 

    <context:component-scan base-package="com.elastic" />
    <elasticsearch:repositories base-package="com.elastic.repository" />
    <elasticsearch:repositories base-package="com.elastic.entity" />


Base package should come first .