我正在创建一个基于Spring的Web应用程序,我需要创建与DynamoDB的连接。每次我尝试,它都会使上下文初始化失败:java.lang.NoClassDefFoundError: com/amazonaws/services/dynamodbv2/AmazonDynamoDB
。
这里没有我使用AmazonDynamoDB的地方。我还删除了静态,以便在初始化之前不会执行。
我的代码是:
@Repository
public class AbstractImplDAO <E> implements IAbstractDAO<E> {
AmazonDynamoDBClient dbClient = new AmazonDynamoDBClient(new ProfileCredentialsProvider("UserName").getCredentials()).withRegion(Regions.US_WEST_2);
DynamoDBMapper mapper = new DynamoDBMapper(dbClient, new DynamoDBMapperConfig(SaveBehavior.CLOBBER));
@Override
public IInfo getData(E entity) {
return null;
}
@Override
public IInfo add(E entity) {
InventoryLog e = new InventoryLog();
e = (InventoryLog) entity;
mapper.save(e);
System.out.println("Print Anything");
IInfo info = new Info();
info.setStatus(true);
return info;
}
@Override
public IInfo update(E entity) {
return null;
}
}
我得到的错误是:
ERROR [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 81) Context initialization failed: java.lang.NoClassDefFoundError: com/amazonaws/services/dynamodbv2/AmazonDynamoDB
at java.lang.Class.getDeclaredConstructors0(Native Method) [rt.jar:1.7.0_79]
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2585) [rt.jar:1.7.0_79]
at java.lang.Class.getDeclaredConstructors(Class.java:1906) [rt.jar:1.7.0_79]
我的申请背景是:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<task:annotation-driven />
<context:component-scan base-package="com.rit.randemmiddleware.*" />
<util:properties id="propertyConfigurer"
location="/WEB-INF/configuration/web/WebConfigLocal.properties" />
<context:property-placeholder properties-ref="propertyConfigurer"
location="/WEB-INF/configuration/Environment.properties,
/WEB-INF/configuration/db/DbConfigLocal.properties" />
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/view/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
请为此提供解决方案。我是新人。如果可能的话请帮我一个例子,这样我就可以在web应用程序中实现DynamoDB。