我实际上正在使用spring Ioc和primefaces开发一个Jsf项目。 当我运行我的项目时,我得到了这个错误,我无法找到原因。这是错误:
Caused by: java.lang.NullPointerException
at com.grh.bean.TypePrimeManager.init(TypePrimeManager.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:346)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:299)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:132)
... 63 more
这是我的托管bean:
package com.grh.bean;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import org.primefaces.context.RequestContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.grh.model.Input;
import com.grh.model.TypPrime;
import com.grh.service.TypeprimeServ;
@Component
@ManagedBean
@Scope("session")
public class TypePrimeManager{
@Autowired
private TypeprimeServ TPS;
private List<TypPrime> tprimes =new ArrayList<TypPrime>();
private TypPrime selectedtype=new TypPrime();
private TypPrime Pr=new TypPrime();
private TypPrime P=new TypPrime();
private List<Input> inputs;
private boolean a=false;
private TypPrime MTypepPrime= new TypPrime();
private List<TypPrime> listTypajouter;
private List<TypPrime> listexistantajout;
private int nbrechampafficher;
private int nbchamps;
private String nb=null;
private TypPrime typSup =new TypPrime();
private List<TypPrime> listTypePrime;
private int n;
private String[] TypeEntr;
@PostConstruct
public void init(){
listTypePrime.clear();
listTypePrime = TPS.TousTypePrime();
}
public int getN() {
return n;
}
public void setN(int n) {
this.n = n;
}
public void setInputs(List<Input> inputs) {
this.inputs = inputs;
}
public List<TypPrime> getListTypePrime() {
return listTypePrime;
}
public void setListTypePrime(List<TypPrime> listTypePrime) {
this.listTypePrime = listTypePrime;
}
public String getNb() {
return nb;
}
public void setNb(String nb) {
this.nb = nb;
}
public TypPrime getSelectedtype() {
return selectedtype;
}
public void setSelectedtype(TypPrime selectedtype) {
this.selectedtype = selectedtype;
}
public int getNbchamps() {
return nbchamps;
}
public void setNbchamps(int nbchamps) {
this.nbchamps = nbchamps;
}
public int getNbrechampafficher() {
return nbrechampafficher;
}
public void setNbrechampafficher(int nbrechampafficher) {
this.nbrechampafficher = nbrechampafficher;
}
public TypPrime getMTypepPrime() {
return MTypepPrime;
}
public void setMTypepPrime(TypPrime mTypepPrime) {
MTypepPrime = mTypepPrime;
}
public String remplirList(){
listTypePrime.addAll(TPS.TousTypePrime());
return "";
}
public TypPrime getTypSup() {
return typSup;
}
public void setTypSup(TypPrime typSup) {
this.typSup = typSup;
}
public TypPrime getPr() {
return Pr;
}
public void setPr(TypPrime pr) {
Pr = pr;
}
public List<TypPrime> getTprimes() {
return tprimes;
}
public void setTprimes(List<TypPrime> tprimes) {
this.tprimes = tprimes;
}
public TypPrime getP() {
return P;
}
public void setP(TypPrime p) {
P = p;
}
public TypeprimeServ getTPS() {
return TPS;
}
public void setTPS(TypeprimeServ tPS) {
TPS = tPS;
}
public List<TypPrime> gettprimes() {
return tprimes;
}
public void settprimes(List<TypPrime> Tprimes) {
tprimes = Tprimes;
}
public boolean isA() {
return a;
}
public void setA(boolean a) {
this.a = a;
}
public String[] getTypeEntr() {
return TypeEntr;
}
public void setTypeEntr(String[] typeEntr) {
TypeEntr = typeEntr;
}
public void traitementAjout(){
}
public List<TypPrime> getListTypajouter() {
return listTypajouter;
}
public void setListTypajouter(List<TypPrime> listTypajouter) {
this.listTypajouter = listTypajouter;
}
public List<TypPrime> getListexistantajout() {
return listexistantajout;
}
public void setListexistantajout(List<TypPrime> listexistantajout) {
this.listexistantajout = listexistantajout;
}
public void traitmenetModifer(){
}
public void traitementSupprimer(){
try{
TPS.supprimerTypeprime(typSup);
FacesContext co = FacesContext.getCurrentInstance();
co.addMessage(null, new FacesMessage("type de prime bien supprimé"));
init();
selectedtype=null;
}catch(Exception e){
FacesContext co = FacesContext.getCurrentInstance();
co.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"Type de prime non supprimé car déjà utilisé", null));
remplirList();
RequestContext.getCurrentInstance().update("carsTable");
}
}
public void champs(){
setTypeEntr(new String[n]);
RequestContext context = RequestContext.getCurrentInstance();
context.execute("PF('ajoutertypeprime').show()");
}
public void add() {
Input input = new Input();
input.setLabel("Input " + (inputs.size() + 1));
inputs.add(input);
}
public List<Input> getInputs() {
return inputs;
}
public void supPrimeType(){
typSup=selectedtype;
RequestContext context = RequestContext.getCurrentInstance();
context.execute("PF('dialogSupprimer').show()");
selectedtype=null;
}
}
这是我的应用程序上下文:
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" >
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/grh"></property>
<!-- property name="url" value="jdbc:mysql://192.168.1.3/grh"></property-->
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource"><ref bean="dataSource" /></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>com.grh.model.Typecredit</value>
<value>com.grh.model.GroupetravailEmploye</value>
<value>com.grh.model.Mission</value>
<value>com.grh.model.Organisme</value>
<value>com.grh.model.Poste</value>
<value>com.grh.model.Etablissement</value>
<value>com.grh.model.TypPrime</value>
<value>com.grh.model.Ville</value>
<value>com.grh.model.Credit</value>
<value>com.grh.model.Configuration</value>
<value>com.grh.model.ExceptionDisponibilite</value>
<value>com.grh.model.Echelon</value>
<value>com.grh.model.TypeSanction</value>
<value>com.grh.model.PosteEmploye</value>
<value>com.grh.model.Contrat</value>
<value>com.grh.model.Grade</value>
<value>com.grh.model.FormationEmploye</value>
<value>com.grh.model.HeureExceptionnelle</value>
<value>com.grh.model.Groupetravail</value>
<value>com.grh.model.Administration</value>
<value>com.grh.model.Prime</value>
<value>com.grh.model.Conjoint</value>
<value>com.grh.model.MissionEmploye</value>
<value>com.grh.model.TypPrimeEchelon</value>
<value>com.grh.model.Diplome</value>
<value>com.grh.model.GradeEmploye</value>
<value>com.grh.model.Sanction</value>
<value>com.grh.model.Document</value>
<value>com.grh.model.Echelle</value>
<value>com.grh.model.EmployeHeureExceptionnelle</value>
<value>com.grh.model.Typeconge</value>
<value>com.grh.model.TypeRetraite</value>
<value>com.grh.model.ConjointEmploye</value>
<value>com.grh.model.Typecontrat</value>
<value>com.grh.model.Formation</value>
<value>com.grh.model.DiplomePoste</value>
<value>com.grh.model.Droit</value>
<value>com.grh.model.Conge</value>
<value>com.grh.model.PrimeEmploye</value>
<value>com.grh.model.Employe</value>
<value>com.grh.model.Enfant</value>
<value>com.grh.model.DiplomePersonnelle</value>
<value>com.grh.model.Typerecrutement</value>
<value>com.grh.model.Pays</value>
<value>com.grh.model.Retraite</value>
<value>com.grh.model.TypeCreditEtablissement</value>
<value>com.grh.model.DiplomeEtablissement</value>
<value>com.grh.model.OrganismeEtablissement</value>
<value>com.grh.model.TypcongeEtablissement</value>
<value>com.grh.model.TypContratEtablissement</value>
<value>com.grh.model.TypRecrutementEtablissement</value>
<value>com.grh.model.TypSanctionEtablissement</value>
<value>com.grh.model.TypretraiteEtabl</value></list>
</property></bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<context:annotation-config/>
<context:component-scan base-package="com.grh"/>
</beans>
我真的很感激任何帮助。