我正在使用Spring Boot 2.1.1和Java 8开发微服务应用程序。此数据库中使用的数据库是AWS DynamoDB。运行我的应用程序时出现以下错误:-
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userProfileJpaRepository': Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
完整的错误日志:-
启动ApplicationContext时出错。要显示条件报告,请在启用“调试”的情况下重新运行您的应用程序。 2019-03-15 15:01:01.148错误20204 --- [main] o.s.boot.SpringApplication:应用程序运行失败
org.springframework.beans.factory.UnsatisfiedDependencyException:在类路径资源[org / springframework / boot / boot / autoconfigure / validation / ValidationAutoConfiguration.class]中创建名称为“ methodValidationPostProcessor”的bean时出错:通过方法“ methodValidationPostProcessor”表达的不满意依赖性参数0;嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名称为'userProfileJpaRepository'的bean时出错:无法解析匹配的构造函数(提示:为简单参数指定index / type / name参数以避免类型歧义) 在org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:769)〜[spring-beans-5.3.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:509)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1288)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)〜[spring-beans-5.3.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)〜[spring-beans-5.3.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:320)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:228)〜[spring-context-5.3.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:707)〜[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)〜[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)〜[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE] 在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE] 在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE] 在org.springframework.boot.SpringApplication.run(SpringApplication.java:316)上[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE] 在org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)上[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE] 在org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)上[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE] 在com.user.profile.UserProfileApplication.main(UserProfileApplication.java:14)[classes /:na] 引起原因:org.springframework.beans.factory.BeanCreationException:创建名称为'userProfileJpaRepository'的bean时出错:无法解析匹配的构造函数(提示:为简单参数指定index / type / name参数以避免类型歧义) 在org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:268)〜[spring-beans-5.3.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1308)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1154)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:974)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:848)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:574)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:514)〜[spring-beans-5.3.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:477)〜[spring-beans-5.3.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeInIncludeAncestors(BeanFactoryUtils.java:227)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1401)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1200)〜[spring-beans-5.3.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1164)〜[spring-beans-5.3.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857)〜[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760)〜[spring-beans-5.3.3.RELEASE.jar:5.1.3.RELEASE] ...省略了19个常见框架
以退出代码1完成的过程
主类文件:-
package com.user.profile;
import org.socialsignin.spring.data.dynamodb.repository.config.EnableDynamoDBRepositories;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan("com.user.profile.jpa") //to scan packages mentioned
@EnableDynamoDBRepositories(basePackages = "com.user.profile.jpa")
public class UserProfileApplication {
public static void main(String[] args) {
SpringApplication.run(UserProfileApplication.class, args);
}
}
POM.xml:-
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.user.profile</groupId>
<artifactId>user-profile</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>user-profile</name>
<description>User Profile</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
<!-- Amazon DynamoDB -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
<version>1.11.470</version>
</dependency>
<!-- Community module for DynamoDB -->
<dependency>
<groupId>com.github.derjust</groupId>
<artifactId>spring-data-dynamodb</artifactId>
<version>4.3.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<finalName>docker-spring-boot</finalName>
</build>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
</project>
application.properties文件:-
amazon.dynamodb.endpoint=http://localhost:8000/
amazon.aws.accesskey=HSGHAD768242
amazon.aws.secretkey=ghjgh677238hjhjhHJJHADU8977JKHKJ
amazon.dynamodb.region="us-west-2"
spring.main.allow-bean-definition-overriding=true
#spring.profiles.active=dev
server.port=8090
JPA存储库:-
package com.user.profile.jpa;
import com.user.profile.model.UserProfileModel;
import org.socialsignin.spring.data.dynamodb.repository.EnableScan;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@EnableScan
public interface UserProfileJpaRepository extends CrudRepository<UserProfileModel, Integer> {
}
DynamoDB配置类:-
package com.user.profile.jpa;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
import com.amazonaws.services.dynamodbv2.document.DynamoDB;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig;
import org.socialsignin.spring.data.dynamodb.repository.config.EnableDynamoDBRepositories;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
@Configuration
@EnableDynamoDBRepositories(basePackages = "com.user.profile.jpa")
public class DynamoDbConfig {
@Value("${amazon.dynamodb.endpoint}")
private String dynamoDbEndPoint;
@Value("${amazon.aws.accesskey}")
private String accessKey;
@Value("${amazon.aws.secretkey}")
private String secretAccessKey;
@Value("${amazon.dynamodb.region}")
private String dynamoDBRegion;
@Bean
public DynamoDBMapperConfig dynamoDBMapperConfig() {
return DynamoDBMapperConfig.DEFAULT;
}
@Bean
public DynamoDBMapper dynamoDBMapper(AmazonDynamoDB amazonDynamoDB, DynamoDBMapperConfig config) {
return new DynamoDBMapper(amazonDynamoDB, config);
}
@Bean
public AmazonDynamoDB amazonDynamoDB() {
return AmazonDynamoDBClientBuilder
.standard()
.withEndpointConfiguration(
new AwsClientBuilder.EndpointConfiguration(dynamoDbEndPoint, dynamoDBRegion))
.build();
}
@Bean
public DynamoDB dynamoDB() {
return new DynamoDB(amazonDynamoDB());
}
}
实体类:-
package com.user.profile.model;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAutoGeneratedKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;
import java.util.UUID;
@DynamoDBTable(tableName = "UserProfileModel")
public class UserProfileModel {
private UUID uuid;
private Integer userId;
private String firstName;
private String lastName;
private String gender;
private int age;
/* public UserProfileModel() {
}
public UserProfileModel(UUID uuid, int userId, String firstName, String lastName, String gender, int age) {
this.uuid = uuid;
this.userId = userId;
this.firstName = firstName;
this.lastName = lastName;
this.gender = gender;
this.age = age;
}*/
public UUID getUuid() {
return uuid;
}
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
@DynamoDBHashKey
@DynamoDBAutoGeneratedKey
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
@DynamoDBAttribute
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@DynamoDBAttribute
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@DynamoDBAttribute
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
@DynamoDBAttribute
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "UserProfileModel{" +
"uuid=" + uuid +
", userId=" + userId +
'}';
}
}
我相信我的JPA存储库声明有问题。 如果您能提出问题的根本原因,我将不胜感激。
欢呼