我在啓動我的應用程序時遇到了問題。彈出錯誤創建bean xStreamMarshaller
當我開始命令mvn碼頭:運行,我得到以下例外:
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,這裏的春天相關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>
我的春天的版本是: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
包。如果有人有任何想法的幫助將不勝感激!
我試過了,但不幸的是問題似乎是一樣的: 'Property'aliases'throw exception;嵌套異常是java.lang.ClassNotFoundException:at.itn.shadowrun.domain.DChars' – Markus
你確切地說,「確保你在應用上下文中有相應的bean爲DChars類。」? 我已經把DChars類放在'at.itn.shadowrun.domain'包中,並像你在示例代碼中那樣設置了prop鍵(我也嘗試過'key =「DChars」''因爲我重命名了'@ XStreamAlias'在DChars類中 – Markus
嘗試向xstreamMarshaller bean添加 。在我的情況下,我在appcontext中爲Domain對象添加了bean。例如,在您的情況下: 在appContext.xml中。 –