How can I initialize a repository with autowired (NullPointer issue)?

I’m currently doing a proof of concept for an hexagonal architecture in which I have three main modules as the following tree project shows :

Architecture hexagonale/
    Business/
        Model/
            Prm
        Ports/
            PrmPort (interface)
            PrmRepository (interface)
        Service/
            PrmService (interface)
            PrmServiceImpl (implements PrmService)
            ServiceFactory (create new PrmServiceImpl)
    Exposition
        Adapters/
            PrmAdapter (implements PrmPort from Business)
        Api/
            PrmController
        Application
        ApplicationConfig (@Configuration, @Bean)
    Infrastructure
        Adapters/
            PrmAdapter (implements PrmRepository from Business) : the goal is to convert data retrieved from Database which is Prm (Infrastructure) to Prm (Business type)
        Models/
            Prm
        Repositories/
            PrmRepository (interface extends JpaRepository)

The problem I’m trying to solve now is that I need to retrieve data from my database

Architecture_Hexagonale/Infrastructure/Repositories/PrmRepository.java:

package fr.enedis.icam.microapp.sample.business.ports;

import fr.enedis.icam.microapp.sample.business.model.Prm;

import java.util.List;

public interface PrmRepository {
    List<Prm> findAll();
}

and to do so I use my PrmAdapter from Infrastructure as following

Architecture_Hexagonale/Infrastructure/Adapters/PrmAdapter.java: **

package fr.enedis.icam.microapp.sample.infrastructure.adapters;

import fr.enedis.icam.microapp.sample.business.model.Prm;
import fr.enedis.icam.microapp.sample.business.ports.PrmRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.ArrayList;
import java.util.List;

@Service
public class PrmAdapter implements PrmRepository {
    public fr.enedis.icam.microapp.sample.infrastructure.repositories.PrmRepository repo;

    public List<Prm> findAll() {
        List<fr.enedis.icam.microapp.sample.infrastructure.models.Prm> infraList = repo.findAll();
        List<Prm> toRet = new ArrayList<>();

        for (fr.enedis.icam.microapp.sample.infrastructure.models.Prm prm : infraList) {
            toRet.add(prm.convert());
        }
        return toRet;
    }
}

The problem is the public fr.enedis.icam.microapp.sample.infrastructure.repositories.PrmRepository repo; is not initialized and returns a NullPointer.** It has to be noted that my business Module doesn't depend of any external components such as databases, framework or any kind of.    I already tried something like: 

package fr.enedis.icam.microapp.sample.infrastructure.adapters;

import fr.enedis.icam.microapp.sample.business.model.Prm;
import fr.enedis.icam.microapp.sample.business.ports.PrmRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;import java.util.List;

@Service
public class PrmAdapter implements PrmRepository {
@Autowiredprivate fr.enedis.icam.microapp.sample.infrastructure.repositories.PrmRepository repo;

public List<Prm> findAll() {     
    List<fr.enedis.icam.microapp.sample.infrastructure.models.Prm> infraList = repo.findAll();    

    List<Prm> toRet = new ArrayList<>();      
    for (fr.enedis.icam.microapp.sample.infrastructure.models.Prm prm : infraList) {         
        toRet.add(prm.convert());     
    }     
    return toRet; 
}

}


package fr.enedis.icam.microapp.sample.application;

import fr.enedis.icam.microapp.sample.application.adapters.PrmAdapter;
import fr.enedis.icam.microapp.sample.business.ports.PrmPort;
import fr.enedis.icam.microapp.sample.business.ports.PrmRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@Configuration
//@EnableJpaRepositories(basePackages = “fr.enedis.icam.microapp.sample.infrastructure.repositories”)
public class ApplicationConfig {
@Bean public PrmPort prmPort() {
return new PrmAdapter();
}

@Bean public PrmRepository prmRepository(){     
    return new fr.enedis.icam.microapp.sample.infrastructure.adapters.PrmAdapter(); 
}

}


But this method gives me missing bean for repository. I also tried using 

package fr.enedis.icam.microapp.sample.application;

import fr.enedis.icam.microapp.sample.application.adapters.PrmAdapter;
import fr.enedis.icam.microapp.sample.business.ports.PrmPort;
import fr.enedis.icam.microapp.sample.business.ports.PrmRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@Configuration@EnableJpaRepositories(basePackages = “fr.enedis.icam.microapp.sample.infrastructure.repositories”)
public class ApplicationConfig {

@Bean
public PrmPort prmPort() {
    return new PrmAdapter();
}

@Bean
public PrmRepository prmRepositoryImpl(){
    return new fr.enedis.icam.microapp.sample.infrastructure.adapters.PrmAdapter();
}

}

New contributor

Kevin rdnv is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật