【问题标题】:Unsatisfied dependency expressed through field (Spring Boot v 1.5.1)通过字段表示的不满足的依赖关系(Spring Boot v 1.5.1)
【发布时间】:2017-08-09 22:51:14
【问题描述】:

我是spring boot和mongoDB的新手,请帮忙。

我通过 mongoTemplate 表达了不满意的依赖关系,我无法找到它的根本原因。下面是它的堆栈跟踪。

"org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'gmailPullHandler': Unsatisfied dependency expressed through field 'gmailPullService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'gmailPullService': Unsatisfied dependency expressed through field 'gmailMailDataRepository'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'gmailMailDataRepositoryImpl': Unsatisfied dependency expressed through field 'mongoTemplate'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mongoTemplate' parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mappingMongoConverter' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mappingMongoConverter' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.StackOverflowError
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
    at com.plash.configurator.Application.main(Application.java:38)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)

由于存在三个不满足的依赖关系,哪一个导致错误,我无法找到它。

注意: gmailMailDataRepository 类由 MongoRepository、GmailMailDataRepositoryCustom 扩展

gmailMailDataRepository:

@Repository
public interface GmailMailDataRepository extends MongoRepository<GmailMailData, String>, GmailMailDataRepositoryCustom {


   {'threadidslist.threadid':?1}{'useremail':?2}")
    List<GmailMailData> getListByThreadidmMsgidEmailid(String messagid, String threadid, String useremail);


    void saveObjectToMsgList(GmailMessages gm, String useremailid, String threadid, String prospectemailid);


}

下面是 GmailMailDataRepositoryCustom 和 GmailMailDataRepositoryImpl:

GmailMailDataRepository 自定义:

    public interface GmailMailDataRepositoryCustom {

    void saveObjectToMsgList(GmailMessages g, String useremailid, String threadid, String prospectemailid);
}

GmailMailDataRepositoryImpl:

public class GmailMailDataRepositoryImpl implements GmailMailDataRepositoryCustom {
// private final MongoOperations operations;


@Autowired
private MongoTemplate mongoTemplate;


Update update = new Update();

@Override
public void saveObjectToMsgList(GmailMessages gm, String useremailid, String threadid, String prospectemailid) {

    Query query = new Query(Criteria.where("useremail").is(useremailid).and("prospectemailid").is(prospectemailid).and("threadidslist.threadid").is(threadid));
    update.push("threadidslist.$.messagelist", gm);
    mongoTemplate.updateFirst(query, update, GmailMailData.class);

}

mongo的Application.properities配置如下:

spring.data.mongodb.host=localhost
spring.data.mongodb.password=#########
spring.data.mongodb.port=27017
spring.data.mongodb.repositories.enabled=true

build.gradle:

compile("org.springframework.boot:spring-boot-starter-data-mongodb")

【问题讨论】:

  • 问题似乎是将pullhandler 命名变量注入pullshandlerservice。您可以将这些课程添加到帖子中吗?
  • 根本原因实际上似乎是MongoDataAutoConfiguration的init方法中的StackOverflowError。也许看看这门课的来源会发现更多的见解?!
  • @dpr 我没有显式配置 mongo 属性,一切都在 enableAutoConfiguration 已经存在的 application.class 下。
  • 为什么void saveObjectToMsgList(GmailMessages gm, String useremailid, String threadid, String prospectemailid);in GmailMailDataRepository 已经在GmailMailDataRepositoryCustom(由GmailMailDataRepository 扩展)中定义?从GmailMailDataRepository删除它
  • 也许您可以将您的修复添加为您自己问题的答案?这可能会帮助遇到与您相同的问题的人,因为修复似乎不太明显......

标签: java spring mongodb spring-boot


【解决方案1】:

问题已解决。这是模型级别的错误。

列表转换错误。

@Data
@Document(collection = "GmailOtherMailData")
public class GmailOtherMailData {
    @Id
    private String id;

    private String useremail;
    private List<GmailOtherThreads> threadidslist;

}

我应该在 List 中投射 GmailOtherThreads 对象,但我使用了其他一些对象。由于错误的转换,我在代码中到处都是错误。

【讨论】:

    猜你喜欢
    • 2022-11-13
    • 1970-01-01
    • 2019-08-14
    • 2019-11-09
    • 2018-11-02
    • 2019-08-03
    • 1970-01-01
    • 2020-02-13
    • 2016-12-21
    相关资源
    最近更新 更多