I'm setting up a project using Spring boot for ioc and Data-Jpa along with JSF but I have a problem with @Autowired
my DAO is not loading.
Does anyone know how to do this setting and where can I be wrong?
Here's my setup:
ApplicationConfigclass
@SpringBootApplication@ComponentScanpublicclassApplicationConfigextendsSpringBootServletInitializer{@OverrideprotectedSpringApplicationBuilderconfigure(SpringApplicationBuilderapplication){returnapplication.sources(ApplicationConfig.class);}@BeanpublicServletRegistrationBeanservletRegistrationBean(){FacesServletservlet=newFacesServlet();ServletRegistrationBeanservletRegistrationBean=newServletRegistrationBean(servlet,"*.xhtml");
return servletRegistrationBean;
}
}
LoginMbController class
@ManagedBean(name = "login")
@Component
public class LoginMBController {
@Autowired
private CustomerDao customerDao;
public void test() {
System.out.println("Hello");
System.out.println(customerDao);
}
}
The customerDao
public interface CustomerDao extends JpaRepository<Customer, Long>{
}
The application.properties
# Show or not log for each sql query
spring.jpa.show-sql = true
# Hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto = update
# Datasource
spring.datasource.jndi-name=java:jboss/datasources/mysqlDS
Login.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
<H2>
<h:outputText value="Login Page" />
</H2>
<h:form>
<p:button value="ok" onclick="#{login.test()}" />
</h:form>
</h:body>
</html>
and my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>CarlosSnackBar</display-name>
<welcome-file-list>
<welcome-file>login.xhtml</welcome-file>
</welcome-file-list>
</web-app>
When I click the "ok" button on the console it will appear "hello null"