이것은 첫 번째 Spring 애플리케이션입니다. 도메인에는 제품 및 제품 유형이라는 두 가지 클래스가 있습니다.Spring 4 + Hibernate 4 + JSF 2.2 + PrimeFaces 4 - 객체 속성에 액세스 할 때 NullPointerException이 발생했습니다.
나는 @Controller
주석을 통해 관리 빈을 액세스하는거야, 그리고 범위는 @Scope("request")
applicationContext.xml이다
<?xml version='1.0' encoding='UTF-8' ?> <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}" />
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="productRepository"
class="com.website.repository.ProductRepository" />
<bean id="productTypeRepository"
class="com.website.repository.ProductTypeRepository" />
<bean id="productMB"
class="com.website.managedbean.ProductMB" />
<bean id="productTypeMB"
class="com.website.managedbean.ProductTypeMB" />
<bean id="product"
class="com.website.model.Product" />
<bean id="productType"
class="com.website.model.ProductType" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean" />
<bean class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven />
jdbc.properties 파일 :
# jdbc.X
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/products
jdbc.username=root
jdbc.password=root
# hibernate.X
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=validate
내 faces-config.xml에는 다음 항목 만 있습니다. 의 ContextLoaderListener와 RequestContextListener :
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
그리고
은 web.xml 파일에 난 두 개의 리스너를 추가했다. DispatcherServlet을 더합니다.ProductRepository는 @Repository
으로 주석을 달고 @PersistenceContext
을 사용합니다.
ProductMB는 ProductRepository를 @Autowired
으로 삽입합니다.
index.xhtml :
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Product</title>
</h:head>
<h:body>
<h:form>
<p:growl id="messages"
globalOnly="true"
autoUpdate="true"
sticky="true" />
<p:panel header="New Product">
<h:panelGrid columns="3">
<p:outputLabel for="product-name"
value="Name:" />
<p:inputText id="product-name"
value="#{productMB.product.name}" />
<p:message for="product-name" />
<p:commandButton value="Insert"
action="#{productMB.save}"
ajax="false" />
</h:panelGrid>
</p:panel>
</h:form>
</h:body>
</html>
P.S : 넷빈즈 8.0
와우, 감사합니다! 나중에 살펴보고 내가 한 것과 비교해 볼 것입니다. – rsb2097
행운을 빌어 요! 희망이 문제를 해결할 수 있습니다 :) –