0

I have a JpaRespository interface like blow,

@Transactional
@Repository
public interface ProductRepository extends JpaRepository<Product, Long> {
    public Product findById(Long id);
    
}

I want to make use this Repository methods from a non container managed class something like below.

public class ProductFactory implements ITestFactory {

    private static ProductFactory instance = new ProductFactory();

    public static ProductFactory getInstance() {

        return instance;
    }

    private ProductFactory() {
    }

    @Override
    public Product getProduct(Long id) {
        // Need to access ProductRepository here
    }

    //.... remaining methods and logic
}

public interface ITestFactory {
    Product getProduct(Long id);
    //.. remaining methods
}

Here getInstance() of ProductFactory is invoked by a platform(in house spring based platform) class which I dont have access to. Please tell me how do I access the Repository methods in this Factory class methods.

Here is the Config class,

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = {
        "com.test.product"
        }, entityManagerFactoryRef = "productSource", transactionManagerRef = "txn_productSource")
public class RepoConfig {
}
4

0 に答える 0