自动变量不适用于mongorepository

时间:2016-07-13 14:23:25

标签: java spring

我正在使用MongoRepository和我创建的Service图层。 @Autowired功能在我的代码中不起作用,不确定我做错了什么。

服务层

@Service
public class SubmissionsService {

    @Autowired
    private SubmissionsRepository submissionsRepository;

    public List < Submissions > findAll() {
        return submissionsRepository.findAll();
    }
    public List < Submissions > findByUserId(ObjectId id) {
        return submissionsRepository.findByUserId(id);
    }
    public List < Submissions > findByStatus(String status) {
        return submissionsRepository.findByStatus(status);
    }
    public Object insert(Submissions obj) {
        return submissionsRepository.insert(obj);
    }

}

正如你所看到的那样,我调用了Autowired,但在测试时返回null。

SRP.java

@Service
public class SRP {
    @Autowired
    private SubmissionsService repository;

    public void step1(Submissions obj) {
        System.out.println(repository);
    }
}

存储库

public interface SubmissionsRepository extends MongoRepository < Submissions, String > {

    public List < Submissions > findAll();
    public List < Submissions > findByUserId(ObjectId userId);
    public List < Submissions > findByStatus(String status);
    // public void save(Submissions object);

}

配置文件

@SpringBootApplication
@Controller
public class UiApplication {

public static void main(String[] args) {
SpringApplication.run(UiApplication.class, args);
new SRP().step1();
}


}

0 个答案:

没有答案