Spring MVC BeanDefinitionStoreException

时间:2016-11-08 06:34:31

标签: spring spring-mvc google-app-engine javabeans pom.xml

我是Spring f / w的新手,我之前已经在ST知道了这个问题。我认为问题出在一些弹簧罐上。但是,所提供的解决方案对我不起作用。 我正在

**ERROR org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [/home/daffy/IdeaProjects/mvc-11-6-12-00/target/mvcjpalab2-0.0.1-SNAPSHOT/WEB-INF/classes/edu/User.class]; nested exception is java.lang.ArrayIndexOutOfBoundsException: 201**

我正在使用 JPA 来保持数据持久性并使用Google-app-engine开发服务器来运行我的应用程序。 我确保我在pom.xml中的spring版本是一致的。

我的 edu.Java

package edu.sjsu.cmpe275.lab2;

import javax.persistence.*;
import java.util.List;

/**
 * Created by daffy on 11/5/16.
 */

@Table(name="USER")
@Entity
public class User {

    public static final String userid = "ID";
    public static final String userfirstname = "FIRSTNAME";
    public static final String userlastname = "LASTNAME";
    public static final String usertitle = "TITLE";
    public static final String useraddress = "ADDRESS";
    public static final String userphones = "PHONES";


    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = userid)
    private String id;

    @Column(name = userfirstname)
    private String firstname;

    @Column(name = userlastname)
    private String lastname;

    @Column(name = usertitle)
    private String title;

    @Embedded
    @Column(name = useraddress)
    private Address address;

    public User(){

    }
    public User(String id, String firstname, String lastname, String title, Address address)
    {
        this.id = id;
        this.firstname = firstname;
        this.lastname = lastname;
        this.title = title;
        this.address = address;
    }


//    @ManyToMany(mappedBy=userphones)
    //@Column(name = userphones)
    //private List<Phone> phones;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getFirstname() {
        return firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public String getLastname() {
        return lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    //public List<Phone> getPhones() {
        //return phones;
    //}

    //public void setPhones(List<Phone> phones) {
        //this.phones = phones;
    //}

}

我的 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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>CMPE275</groupId>
    <artifactId>mvcjpalab2</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>mvcjpalab2</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

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

        <!-- Spring Dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <version>1.4.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>1.4.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.31</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <version>1.4.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>

    </dependencies>
</project>

分别是 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>Lab2</display-name>
   <!-- <context-param>
        <param-name>contextClass</param-name>
        <param-value>
            org.springframework.web.context.support.AnnotationConfigWebApplicationContext
        </param-value>
    </context-param>-->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>springservlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>springservlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

弹簧servlet.xml中

<?xml version="1.0" encoding="windows-1252"?>
<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.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.0.xsd
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

    <!-- Use @Component annotations for bean definitions -->
    <context:component-scan base-package="edu"/>

    <!-- Use @Controller annotations for MVC controller definitions -->
    <mvc:annotation-driven />

    <!-- Add JPA support -->
    <bean id="emf" class=
            "org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="loadTimeWeaver">
            <bean class=
                          "org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
        </property>
    </bean>

    <!-- Add Transaction support -->
    <bean id="myTxManager"
          class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="emf"/>
    </bean>

    <!-- Use @Transaction annotations for managing transactions -->
    <tx:annotation-driven transaction-manager="myTxManager" />

    <!-- View resolver -->
    <bean class=
                  "org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/*.jsp"/>
    </bean>

</beans>

项目文件夹中 mvn:dependency 的结果是:

mvn dependency:tree
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for CMPE275:mvcjpalab2:war:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.scope' for org.springframework:spring-framework-bom:pom must be one of [provided, compile, runtime, test, system] but is 'import'. @ line 89, column 16
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building mvcjpalab2 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ mvcjpalab2 ---
[INFO] CMPE275:mvcjpalab2:war:0.0.1-SNAPSHOT
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.2.7.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.2.7.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:1.2.7.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.2.7.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.2.7.RELEASE:compile
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.12:compile
[INFO] |  |  |  +- org.slf4j:log4j-over-slf4j:jar:1.7.12:compile
[INFO] |  |  |  \- ch.qos.logback:logback-classic:jar:1.1.3:compile
[INFO] |  |  |     \- ch.qos.logback:logback-core:jar:1.1.3:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.14:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:1.2.7.RELEASE:compile
[INFO] |  |  +- org.aspectj:aspectjrt:jar:1.8.7:compile
[INFO] |  |  \- org.aspectj:aspectjweaver:jar:1.8.7:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.2.7.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-jdbc:jar:4.1.8.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat:tomcat-jdbc:jar:8.0.28:compile
[INFO] |  |  |  \- org.apache.tomcat:tomcat-juli:jar:8.0.28:compile
[INFO] |  |  \- org.springframework:spring-tx:jar:4.1.8.RELEASE:compile
[INFO] |  +- org.hibernate:hibernate-entitymanager:jar:4.3.11.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
[INFO] |  |  +- org.hibernate:hibernate-core:jar:4.3.11.Final:compile
[INFO] |  |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  |  \- org.jboss:jandex:jar:1.1.0.Final:compile
[INFO] |  |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] |  |  +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.5.Final:compile
[INFO] |  |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  |  \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] |  +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] |  +- org.springframework:spring-orm:jar:4.1.8.RELEASE:compile
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:1.7.4.RELEASE:compile
[INFO] |  |  +- org.springframework.data:spring-data-commons:jar:1.9.4.RELEASE:compile
[INFO] |  |  +- org.slf4j:slf4j-api:jar:1.7.12:compile
[INFO] |  |  \- org.slf4j:jcl-over-slf4j:jar:1.7.12:compile
[INFO] |  \- org.springframework:spring-aspects:jar:4.1.8.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.2.7.RELEASE:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.4.6:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.4.0:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.4.6:compile
[INFO] |  +- org.hibernate:hibernate-validator:jar:5.1.3.Final:compile
[INFO] |  |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |  \- com.fasterxml:classmate:jar:1.0.0:compile
[INFO] |  +- org.springframework:spring-web:jar:4.1.8.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:4.1.8.RELEASE:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.31:compile
[INFO] +- commons-dbcp:commons-dbcp:jar:1.4:compile
[INFO] |  \- commons-pool:commons-pool:jar:1.5.4:compile
[INFO] +- jstl:jstl:jar:1.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.2.7.RELEASE:compile
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.0.28:compile
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.0.28:compile
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:8.0.28:compile
[INFO] |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.0.28:compile
[INFO] +- org.springframework:spring-context:jar:4.2.5.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.2.5.RELEASE:compile
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.2.5.RELEASE:compile
[INFO] |  \- org.springframework:spring-expression:jar:4.2.5.RELEASE:compile
[INFO] +- javax.servlet:javax.servlet-api:jar:3.1.0:compile
[INFO] +- org.springframework:spring-core:jar:4.2.5.RELEASE:compile
[INFO] |  \- commons-logging:commons-logging:jar:1.2:compile
[INFO] \- org.springframework:spring-framework-bom:pom:4.2.5.RELEASE:import
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.672 s
[INFO] Finished at: 2016-11-07T22:11:33-08:00
[INFO] Final Memory: 16M/212M
[INFO] ------------------------------------------------------------------------

任何帮助我哪里出错了?我几个小时就遇到了这个问题。

0 个答案:

没有答案