Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring引导与MongoDB的集成_Java_Spring_Mongodb_Spring Mvc_Spring Boot - Fatal编程技术网

Java Spring引导与MongoDB的集成

Java Spring引导与MongoDB的集成,java,spring,mongodb,spring-mvc,spring-boot,Java,Spring,Mongodb,Spring Mvc,Spring Boot,我第一次尝试将monodb与我的springBoot应用程序集成,但我遇到了错误 我的代码在下面 package com.myProject.customerview; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotatio

我第一次尝试将monodb与我的springBoot应用程序集成,但我遇到了错误 我的代码在下面

package com.myProject.customerview;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableScheduling
@ImportResource("classpath*:spring/application-context.xml")
@ComponentScan({ "com.myproject.payments", "com.myproject.customerview" })
// @EnableJpaRepositories("com.myproject.customerview.repository")
@EnableMongoRepositories
@SpringBootApplication
public class CustomerViewApplication {

    public static void main(String args[]) {
        SpringApplication application = new SpringApplication(
                CustomerViewApplication.class);
        application.run(args);
    }

}
和控制器

package com.myproject.customerview.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.myproject.customerview.constants.RestURIConstants;
import com.myproject.customerview.response.ServiceResponse;
import com.myproject.customerview.service.CustomerViewService;

@RestController
@RequestMapping(RestURIConstants.CUSTOMER_VIEW)
public class CustomerViewController {

    @Autowired
    private CustomerViewService customerViewService ;
       @RequestMapping(value = RestURIConstants.USER_ID, method = RequestMethod.GET)
       public ServiceResponse<String> getMirrorAccountReport(
                @PathVariable("userId") String userId, HttpServletRequest servletRequest)
                throws Exception {
          ServiceResponse<String> serviceResponse = new ServiceResponse<String>();
          String response = "success:" ;
                  customerViewService.saveCustomerViewEntity();
          serviceResponse.setResponse(response);
          return serviceResponse;
       }
}
dao接口层

package com.myproject.customerview.dao;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.springframework.data.domain.Sort;

import com.myproject.customerview.entity.CustomerViewEntity;

public interface CustomerViewMongoDao {
    public void saveCustomerView(CustomerViewEntity entity) ;
}
其含义

package com.myproject.customerview.dao.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Repository;

import com.myproject.customerview.constants.CustomerViewConstants;
import com.myproject.customerview.dao.CustomerViewMongoDao;
import com.myproject.customerview.entity.CustomerViewEntity;

@Repository
public class CustomerViewMongoDaoImpl implements CustomerViewMongoDao{

    @Autowired
    MongoTemplate mongoTemplate ;   
    @Override
    public void saveCustomerView(CustomerViewEntity entity) {
        mongoTemplate.insert(entity, CustomerViewConstants.CUSTOMER_VIEW_COLLECTION);
    }
}
其存储库

package com.myproject.customerview.repository;

import org.springframework.data.mongodb.repository.MongoRepository;

import com.myproject.customerview.dao.CustomerViewMongoDao;
import com.myproject.customerview.entity.CustomerViewEntity;

public interface CustomerViewRepository extends MongoRepository<CustomerViewEntity,String>, CustomerViewMongoDao {


}

我在pom.xml中错误地添加了此依赖项

     <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-mongodb</artifactId>
        <version>1.8.0.RELEASE</version>
     </dependency>

org.springframework.data
spring数据mongodb
1.8.0.1发布
当我使用

     <dependency>
        <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>

org.springframework.boot
spring启动程序数据mongodb

我的项目开始运行良好。

代码太多,只提供所需内容。在这里阅读:我找到了解决方案,问题不复存在。如果你自己找到了答案,最好在下面提供答案,以防有人有类似的问题。
java.lang.IllegalStateException: Failed to introspect annotations: class org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfigureRegistrar$EnableMongoRepositoriesConfiguration
     <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-mongodb</artifactId>
        <version>1.8.0.RELEASE</version>
     </dependency>
     <dependency>
        <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>