0
I’m having a problem in a JSF test, basically I have the entity, the service and the view, I couldn’t find anything that would help me solve.
In view, I want to call my service by Managedproperty so:
@ManagedBean
@ViewScoped
@Getter
@Setter
public class EpiView implements Serializable {
@ManagedProperty(value = "#{epiService}")
private EpiService epiService;
private Epi epi;
@PostConstruct
public void inicia() {
epi = epiService.epiById();
}
}
and my service:
@Service
public class EpiService {
public Epi epiById() {
Epi epi = new Epi();
epi.setId(new EpiPK());
epi.getId().setCenCust("13.02");
epi.getId().setProduto("Bomba");
epi.setQuantidadeDias(15);
epi.setQuantidadeRetirada(1000);
epi.setCategoria("Veneno");
epi.setQntTroca(200);
return epi;
}
}
I’m not using bank is just a test, but when the page goes up I have one NullPointerException
, the service is not being instantiated, if I create the instance in hand epiService = new EpiService();
it works and is displayed on the page normally, I believe it is a problem in dependency injection, I tried also to use the @Autowired
, but the service comes null
likewise.
The project is in Eclipse Version: 2019-03 (4.11.0) I am using Maven with the following dependencies.
jsf-api-2.2.12.jar jsf-impl-2.2.12.jar javax.Servlet-api-3. 0.1.jar spring-web-4.3.9.RELEASE. jar spring-aop-4.3.9.RELEASE. jar spring-Beans-4.3.9.RELEASE. jar spring-context-4.3.9.RELEASE. jar spring-Expression-4.3.9.RELEASE. jar spring-core-4.3.9.RELEASE. jar Commons-logging-1.2. jar Lombok-1.18.8.jar cdi-api-1.2. jar javax.el-api-3. 0.0.jar javax.Interceptor-api-1. 2.jar
What is your configuration of
el-resolver
?– nullptr
What if you write down the Episervice service with: "@Managedbean(name="epiService")?. To use managedProperty I believe you have to write it down anyway.
– Brother
Anything, take a look at this guide to see its dependencies as well. https://www.baeldung.com/spring-jsf
– Brother