Spring启动Data-JPA和JSF Java Config

时间:2015-07-10 04:39:00

标签: java spring spring-boot

我正在使用Spring引导for ioc和Data-Jpa与JSF建立一个项目,但我在@Autowired我的DAO没有收费时遇到了一些问题。

有人知道如何设置此设置以及我可能会丢失的位置吗?

按照我的设置

ApplicationConfig类

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();
}
}

loginMbController类

package br.com.proenca.snackbar.controller;

@ManagedBean(name = "login")
@Controller
public class LoginMBController {

@Autowired
private CustomerDao customerDao;

public void test() {
    System.out.println("Hello");
    System.out.println(customerDao);
}
}

CustomerDao

package br.com.proenca.snackbar.dao;

public interface CustomerDao extends JpaRepository<Customer, Long>{

}

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

<!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 null”中显示

0 个答案:

没有答案