我是Spring的新手,请任何人都可以帮助解决此异常。
例外:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityDAO' defined in class path resource [springapp-servlet.xml]: Cannot resolve reference to bean 'configDetails' while setting bean property 'configDetails'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configDetails' defined in class path resource [springapp-servlet.xml]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.taphius.databridge.deserializer.DataSourcerConfigDetails]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: com/google/gson/GsonBuilder
这是我的主要课程
public class MainApp {
final static Logger logger = Logger.getLogger(MainApp.class);
public static String FLUME_CONF_DIR = "";
public static void main(String[] args) {
new ClassPathXmlApplicationContext("springapp-servlet.xml");
logger.info("Application context loaded successfully.");
}
}
springapp-servlet.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:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.3.xsd">
<!-- the application context definition for the springapp DispatcherServlet -->
<task:annotation-driven />
<bean id="entityDAO" class="com.taphius.databridge.dao.EntityDefinationDAO">
<property name="configDetails" ref="configDetails" />
</bean>
<bean id="configDetails"
class="com.taphius.databridge.deserializer.DataSourcerConfigDetails">
<constructor-arg>
<value type="java.lang.Class">com.taphius.databridge.model.DataSourcerAttributes
</value>
</constructor-arg>
</bean>
<bean id="dataChecker" class="com.taphius.datachecker.FileChecker"
init-method="init">
<property name="entityDAO" ref="entityDAO" />
</bean>
<bean id="notifyChecker" class="com.taphius.pipeline.notification.PipelineNotifyWatcher"
init-method="init">
<property name="dataChecker" ref="dataChecker" />
</bean>
<bean id="scheduledJob" class="com.taphius.databridge.scheduler.ScheduledDBPoller">
<property name="task" ref="task" />
</bean>
<bean id="task" class="com.taphius.databridge.scheduler.CustomTask">
<property name="entity" ref="entityDAO" />
<property name="dataChecker" ref="dataChecker" />
</bean>
<bean name="runMeJob"
class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass"
value="com.taphius.databridge.scheduler.ScheduledDBPoller" />
<property name="jobDataAsMap">
<map>
<entry key="task" value-ref="task" />
</map>
</property>
<property name="durability" value="true"></property>
</bean>
<!-- Cron Trigger, run every 5 minutes -->
<bean id="cronTrigger"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="runMeJob" />
<property name="cronExpression" value="0 0/2 * * * ?" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobDetails">
<list>
<ref bean="runMeJob" />
</list>
</property>
<property name="triggers">
<list>
<ref bean="cronTrigger" />
</list>
</property>
</bean>
</beans>
答案 0 :(得分:4)
你错误地在你的类路径中包含类com/google/gson/GsonBuilder
的jar。将以下依赖项添加到pom.xml:
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.1</version>
</dependency>