rafek1241 / Patronage-17-java

Patronage Second task
0 stars 0 forks source link

Code style #2

Open mlotysz opened 7 years ago

mlotysz commented 7 years ago
rafek1241 commented 7 years ago

@mlotysz I need some help with private static PriceCatDao priceCatDao = new PriceCatDao();. Can i make a object of this class in MovieDao.java or should i use @Autowired ? When i do that - it's making an error about bean.

mlotysz commented 7 years ago

https://spring.io/blog/2016/03/04/core-container-refinements-in-spring-framework-4-3 (Short version: use constructor injection, remove static, add final, optionally remove Autowired)

rafek1241 commented 7 years ago

It doesn't work for me. Pics: image

rafek1241 commented 7 years ago

@mlotysz I will leave it now. Because i need more explain. I can't use it to static movies variable so i change it on final. It's still doesn't work so i will abandon this issue to make other be success. I'm waiting for your suggestions. `(add @you to highlight this issue)

mlotysz commented 7 years ago

Sure. The way you initialize movies map is wrong. You could use InitializingBean or @PostConstruct instead: http://stackoverflow.com/a/30726748 (or rewrite it to plain Java code, use static blocks...)