I saw that injecting ShopRepo with @Autowire annotation is working but when I try to do it with xml sometimes it works and sometimes it doesn't (also, intellij says that I cannot use an abstract bean as a property). Why it is working with the annotation and with the xml config doesn't always work (which is the difference)? And how could I make it work with xml config?
The code looks like this:
public interface ShopRepo extends JpaRepository<Product, Long> {
@Override
Optional<Product> findById(Long aLong);
}
public class ShopController {
//@Autowired
private ShopRepo shopRepo;
public void setShopRepo(ShopRepo shopRepo) {
this.shopRepo = shopRepo;
}
public Product findProduct(Long id) {
return shopRepo.findById(1l).orElse(new Product());
}
}
<jpa:repositories base-package="com.example.shop.repository"/>
<bean id="shopRepo" class="com.example.shop.repository.ShopRepo" abstract="true"/>
<bean id="shopController" class="com.example.shop.controller.ShopController">
<property name="shopRepo" ref="shopRepo"/>
</bean>