Spring引导数据JPA和JSF Java配置
我正在建立一个项目,使用Spring boot for ioc和带有JSF的数据Jpa,但是@Autowiredmy DAO不收费,我有一个小问题 有人知道如何设置,我可能会错过什么 遵循我的设置 应用程序配置类Spring引导数据JPA和JSF Java配置,java,spring,spring-boot,Java,Spring,Spring Boot,我正在建立一个项目,使用Spring boot for ioc和带有JSF的数据Jpa,但是@Autowiredmy DAO不收费,我有一个小问题 有人知道如何设置,我可能会错过什么 遵循我的设置 应用程序配置类 package br.com.proenca.snackbar; @SpringBootApplication @ComponentScan public class ApplicationConfig extends SpringBootServletInitializer {
package br.com.proenca.snackbar;
@SpringBootApplication
@ComponentScan
public class ApplicationConfig extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ApplicationConfig.class);
}
@Bean
public FacesServlet facesServlet() {
return new FacesServlet();
}
@Bean
public ServletRegistrationBean facesServletRegistration() {
ServletRegistrationBean registration = new ServletRegistrationBean(facesServlet(), "*.xhtml");
registration.setName("FacesServlet");
return registration;
}
@Bean
public ServletListenerRegistrationBean<ConfigureListener> jsfConfigureListener() {
return new ServletListenerRegistrationBean<ConfigureListener>(new ConfigureListener());
}
@Bean
public ELResolver elResolver() {
return new SpringBeanFacesELResolver();
}
}
顾客道
package br.com.proenca.snackbar.dao;
public interface CustomerDao extends JpaRepository<Customer, Long>{
}
login.xhtml
<!DOCTYPE html>
<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>
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>
测试方法只是在控制台中显示Hello nullDAO实现类在哪里?尝试在ApplicationConfig类上使用@EnableAutoConfiguration SPRING-DATA为我们创建一个默认DAO实现。此实现获取JpaRepository接口上声明的所有默认方法。而注释SpringBootApplication包含EnableAutoConfiguration。我已经尝试使用componentScan传递所有包,启用配置AutoConfiguration和componentScan um我的应用程序配置类,但没有任何效果。。。我不知道为什么,但是DAO类没有被Spring上下文加载。
<!DOCTYPE html>
<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>
<?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>