0

我在启动我的应用程序时遇到问题。

当我启动mvn jetty:run时,出现以下异常

2013-08-21 12:14:59.977:WARN:oejw.WebAppContext:Failed startup of context 
o.m.j.p.JettyWebAppContext{/,file:/Users/markus/Documents/workspace/shadowrunV3_gui/src/main/webapp/},file:/Users/markus/Documents/workspace/shadowrunV3_gui/src/main/webapp/
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restTemplate' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot create inner bean 'org.springframework.http.converter.xml.MarshallingHttpMessageConverter#3744cc2c' of type [org.springframework.http.converter.xml.MarshallingHttpMessageConverter] while setting bean property 'messageConverters' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.http.converter.xml.MarshallingHttpMessageConverter#3744cc2c' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'xStreamMarshaller' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xStreamMarshaller' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.util.ArrayList' to required type 'java.lang.Class[]' for property 'annotatedClasses'; nested exception is java.lang.IllegalArgumentException: Cannot find class [at.itn.shadowrun.domain.DChars]

我的 applicationContext.xml:

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jndi="http://www.springframework.org/schema/jndi"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 
http://www.springframework.org/schema/tx  
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context  
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jndi 
http://www.springframework.org/schema/jndi/spring-jndi-3.2.xsd 
http://www.springframework.org/schema/util 
http://www.springframework.org/schema/util/spring-util-3.2.xsd">
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
    <property name="messageConverters">
        <list>
            <bean
                class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
                <constructor-arg>
                    <ref bean="xStreamMarshaller" />
                </constructor-arg>
            </bean>
        </list>
    </property>
</bean>
<bean id="xStreamMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller">
    <property name="annotatedClasses">
        <list>
            <value>at.itn.shadowrun.domain.DChars</value>
            <!-- other classes (the package is correct) -->
        </list>
    </property>
</bean>

    <!-- from an old configuration, from my understanding I dont need this part anymore, but since I'm not sure here it is: -->
<bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
        <property name="annotatedClasses">
            <list>
                <value>
                    at.itn.shadowrun.domain.DChars
                </value>
                <!-- other classes -->
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    ${hibernate.dialect}
                </prop>
            </props>
        </property>
    </bean>

我的 DChars 课程:

package at.itn.shadowrun.domain;

@Entity
@Table(name = "D_CHARS")
@XStreamAlias("DChars")
public class DChars implements DomainObject {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long                id;
// etc..

为了确保我没有在 pom 中做错什么,这里是spring 相关的 pom

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

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

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>org.springframework.beans</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-oxm</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring.version}</version>
    </dependency>

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

我的 Spring 版本是:3.2.3.RELEASE

据我了解,at.itn.shadowrun.domain.DChars找不到该类,但我不明白为什么。它肯定在正确的包装中!

任何帮助将非常感激!谢谢你!

编辑:我更改了@XStreamAlias("DChars")(调用了 db 类D_CHARS,但在 applicationContext 中我将其称为DChars。但不幸的是它没有帮助

edit2:因为我不知道问题出在哪里,并且想确保我没有忽略applicationContext.xml中的一个严重错误,所以我将在此处添加完整文件:

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jndi="http://www.springframework.org/schema/jndi" xmlns:util="http://www.springframework.org/schema/util"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oxm="http://www.springframework.org/schema/oxm"
    xmlns:context="http://www.springframework.org/schema/context"
    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/tx  
    http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/context  
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/jndi 
    http://www.springframework.org/schema/jndi/spring-jndi.xsd 
    http://www.springframework.org/schema/util 
    http://www.springframework.org/schema/util/spring-util.xsd
    http://www.springframework.org/schema/oxm
    http://www.springframework.org/schema/oxm/spring-oxm.xsd
    http://www.springframework.org/schema/security  
    http://www.springframework.org/schema/security/spring-security.xsd">

    <context:component-scan base-package="at.itn.shadowrun.gui.service." />

    <bean id="placeholderConfig"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>/WEB-INF/application.properties</value>
        </property>
        <property name="systemPropertiesModeName">
            <value>SYSTEM_PROPERTIES_MODE_OVERRIDE</value>
        </property>
    </bean>

    <bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
        <property name="messageConverters">
            <list>
                <bean
                    class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
                    <constructor-arg>
                        <ref bean="xStreamMarshaller" />
                    </constructor-arg>
                </bean>
            </list>
        </property>
    </bean>

    <bean id="xStreamMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller">
        <property name="aliases">
            <props>
                <prop key="DChars">at.itn.shadowrun.domain.DChars </prop>
            </props>
        </property>
    </bean>

    <bean id="log4jInitialization"
        class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetClass" value="org.springframework.util.Log4jConfigurer" />
        <property name="targetMethod" value="initLogging" />
        <property name="arguments">
            <list>
                <value>/WEB-INF/log4j.properties</value>
            </list>
        </property>
    </bean>

    <bean id="wicketApplication" class="at.itn.shadowrun.ShadowrunApplication">
    </bean>

    <!-- tells Spring to put transactional advice on any class or method that 
        has an @Transactional annotation on it -->
    <tx:annotation-driven />

    </beans>

我仍然没有得到问题,因为文件DChars肯定在at.itn.shadowrun.domain包中。如果有人有任何想法帮助将不胜感激!

4

1 回答 1

0

更改 xStreamMarshaller 如下:

   <bean id="xstreamMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller">
    <property name="aliases">
        <props>
            <prop key="D_CHARS">at.itn.shadowrun.domain.DChars </prop>
        </props>
    </property>
    </bean>

并确保在 DChars 类的应用程序上下文中有相应的 bean。

于 2013-08-21T13:57:24.230 回答