Я создал простое приложение, использующее JSF и управляемые bean-компоненты. Из управляемого bean-компонента я пытаюсь создать экземпляр весеннего компонента, который хранит данные в базе данных. Однако "@Autowired" аннотаций не кажется работать, так как я получаю nullPointerExcpetion:Впрыск с пружиной в управляемом компоненте:
javax.faces.el.EvaluationException: java.lang.NullPointerException
Проблема появляется, когда есть вызов authenticationComponent. аутентификации() метод
RMQ: Я проверил методы ClientService и все хорошо
управляемый компонент:
@ManagedBean(name="authenticationComponent")
@RequestScoped
public class AuthenticationComponent implements Serializable {
private static final long serialVersionUID = -5085727127290746426L;
private static final String SUCCESS = "success";
private static final String ERROR = "error";
@Autowired
ClientService clientService;
Client client;
String clientName;
String clientPass;
public String authenticate() {
client = clientService.authenticate(clientName, clientPass);
if (client != null) {
return SUCCESS;
}
return ERROR;
}
authentification.xhtml
<p:inputText id="userName" required="true" label="User Name" title="Enter Your Name !" value="#{authenticationComponent.clientName}"/> <p:tooltip for="userName" styleClass="tooltip" showEvent="focus" hideEvent="blur" /> <h:panelGroup> <h:outputText value="User Password : " /> <h:outputText style="color:red" value="* " /> </h:panelGroup> <p:inputText id="userPass" required="true" label="User Password" title="Enter Your Password !" value="#{authenticationComponent.clientPass}" /> <!-- label option is needed for messages component --> <p:tooltip for="userPass" styleClass="tooltip" showEvent="focus" hideEvent="blur" /> <p:commandButton id="submitLoginButton" update="loginPanelGrid,messages" value="Sign In" icon="ui-icon-check" action="#{authenticationComponent.authenticate()}" /> <p:commandButton id="newUserButton" update="loginPanelGrid,messages" value="Sign Up" icon="ui-icon-plus" />
ApplicationContext:
<bean id="clientService" class="com.webapp.service.ClientServiceImpl">
<property name="clientDao" ref="clientDao" />
</bean>
<bean id="genericDao" class="com.webapp.dao.GenericDaoImpl" abstract="true" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="clientDao" class="com.webapp.dao.ClientDaoImpl" parent="genericDao">
<constructor-arg ref="client" />
</bean>
<bean id="client" class="com.webapp.model.Client"/>
Вы смешиваете управляемые фасолью JSF с фасолью весны. @Autowired не будет обнаружен весной, потому что компонент создается из контекста приложения с помощью структуры JSF. – ElderMael
Благодарю вас, используйте то, что затем ввести ClientService? –