1

我是 JSF 和 Spring 的新手。我的任务是通过集成 JSF2.0 和 Spring3.0 来构建一个简单的应用程序。所以我创建了这些类
,我创建了 MasterSearch.xhtml,它们只需要输入

                    <table>   
                    <h:form> 
                        <tr><td>Service Number</td>
                            <td>
                            <h:inputText id="txtMasterServiceNumber" styleClass="text-box" value="#{masterSearch.serviceNumber}" validatorMessage="Invalid input"></td>
                            <f:validateRegex pattern="[A-Za-z0-9]{0,40}"/>
                            </h:inputText>
                            <h:message for="txtMasterServiceNumber" />

                            <h:commandButton id="btnMasterSearch"  type="submit" value="Search" styleClass="submitButton"  action="#{masterSearch.findPerson}"></h:commandButton>


                        </h:form>
                </table> 

现在它将提交到 masterSearch.findPerson
这是 masterSearch bean

   package com.delta.searchbeans;

import java.util.ArrayList;

import javax.annotation.Resource;

import com.delta.resultbeans.MasterSearchResult;
import com.delta.service.MasterSearchService;

public class MasterSearch {

    @Resource(name="personService")
    private MasterSearchService personService;

    String serviceNumber;
    String rank;
    String fullName;
    String CNICNumber;
    String phoneNumber;
    String emailAddress;
    ArrayList<MasterSearchResult> masterSearchResultList;

    public ArrayList<MasterSearchResult> getMasterSearchResultList() {
        return masterSearchResultList;
    }

    public void setMasterSearchResultList(
            ArrayList<MasterSearchResult> masterSearchResultList) {
        this.masterSearchResultList = masterSearchResultList;
    }

    public MasterSearch() {
        System.out.println("Bean initialized ...");
    }

    public String getServiceNumber() {
        return serviceNumber;
    }
    public void setServiceNumber(String serviceNumber) {
        this.serviceNumber = serviceNumber;
    }
    public String getRank() {
        return rank;
    }
    public void setRank(String rank) {
        this.rank = rank;
    }
    public String getFullName() {
        return fullName;
    }
    public void setFullName(String fullName) {
        this.fullName = fullName;
    }
    public String getCNICNumber() {
        return CNICNumber;
    }
    public void setCNICNumber(String cNICNumber) {
        CNICNumber = cNICNumber;
    }
    public String getPhoneNumber() {
        return phoneNumber;
    }
    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }
    public String getEmailAddress() {
        return emailAddress;
    }
    public void setEmailAddress(String emailAddress) {
        this.emailAddress = emailAddress;
    }


    public String findPerson(){

        System.out.println("In person findperson");
        masterSearchResultList = (ArrayList<MasterSearchResult>) personService.getAll();
        System.out.println("Printed By controller: "+masterSearchResultList.get(0).getServiceNumber());
        System.out.println("Printed By controller: "+masterSearchResultList.get(1).getServiceNumber());
        return "personfound";

    }


}

然后 findPerson 将把它传递给基本上是一个 DAO 类并包含 Datasource 等的springService方法 masterSearchResultList = (ArrayList<MasterSearchResult>) personService.getAll(); ,该方法返回包含从 DB 中选取的值的列表......
我在我的 MasterSearch.java 类中获取值,在代码中你可以看到我我正在打印它们,它们打印得很好。所以我将该列表分配给我的 MasterSearch 属性 MasterSearchResultList,但是当我在下一个页面上得到这个列表时(found.jsp),如下所示

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<f:view>

<h1>
  <c:forEach var="person" items="${masterSearch.masterSearchResultList}">
<tr>
<td><h:outputText value="#{person.serviceNumber}"></h:outputText>
</td>
</tr>
</c:forEach>
</h1>
</f:view>
</body>
</html>

然后:(我得到这个错误页面

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception 
org.apache.jasper.JasperException: com.sun.faces.mgbean.ManagedBeanCreationException: An error occurred performing resource injection on managed bean masterSearch

root cause 
com.sun.faces.mgbean.ManagedBeanCreationException: An error occurred performing resource injection on managed bean masterSearch

root cause 
com.sun.faces.spi.InjectionProviderException: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Env-Prop: personService@Field-Injectable Resource. Class name = com.delta.searchbeans.MasterSearch Field name=personService@java.lang.String@personService@@ into class com.delta.searchbeans.MasterSearch: Lookup failed for 'java:comp/env/personService' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}

root cause 
com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Env-Prop: personService@Field-Injectable Resource. Class name = com.delta.searchbeans.MasterSearch Field name=personService@java.lang.String@personService@@ into class com.delta.searchbeans.MasterSearch: Lookup failed for 'java:comp/env/personService' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}

root cause 
javax.naming.NamingException: Lookup failed for 'java:comp/env/personService' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Lookup failed for 'personService' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming, com.sun.enterprise.naming.logicalName=java:comp/env/personService} [Root exception is javax.naming.NameNotFoundException: personService not found]]

root cause 
javax.naming.NamingException: Lookup failed for 'personService' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming, com.sun.enterprise.naming.logicalName=java:comp/env/personService} [Root exception is javax.naming.NameNotFoundException: personService not found]

root cause 
javax.naming.NameNotFoundException: personService not found

和控制台中的这个错误

WARNING: ApplicationDispatcher[/DSVAR] PWC1231: Servlet.service() for servlet jsp threw exception
javax.naming.NameNotFoundException: personService not found
    at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:248)
    at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:215)
    at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:77)
    at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:119)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:505)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at com.sun.enterprise.naming.util.JndiNamingObjectFactory.create(JndiNamingObjectFactory.java:90)
    at com.sun.enterprise.container.common.impl.ComponentEnvManagerImpl$1.create(ComponentEnvManagerImpl.java:653)
    at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:776)
    at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:744)
    at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:169)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:498)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:599)
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:470)
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:171)
    at org.glassfish.faces.integration.GlassFishInjectionProvider.inject(GlassFishInjectionProvider.java:184)
    at com.sun.faces.mgbean.BeanBuilder.injectResources(BeanBuilder.java:205)
    at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:103)
    at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
    at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
    at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
    at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at com.sun.faces.el.ChainTypeCompositeELResolver.getValue(ChainTypeCompositeELResolver.java:94)
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:188)
    at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:103)
    at com.sun.el.parser.AstValue.getValue(AstValue.java:179)
    at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:224)
    at org.apache.jasper.runtime.PageContextImpl.evaluateExpression(PageContextImpl.java:1009)
    at org.apache.jsp.WebPages.SearchPages.found_jsp._jspx_meth_c_forEach_0(found_jsp.java:154)
    at org.apache.jsp.WebPages.SearchPages.found_jsp._jspx_meth_f_view_0(found_jsp.java:118)
    at org.apache.jsp.WebPages.SearchPages.found_jsp._jspService(found_jsp.java:79)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
    at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:809)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:671)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:505)
    at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:476)
    at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:355)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:305)
    at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:546)
    at com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandlingStrategy.java:364)
    at com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:154)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)

WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
javax.naming.NameNotFoundException: personService not found
    at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:248)
    at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:215)
    at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:77)
    at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:119)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:505)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at com.sun.enterprise.naming.util.JndiNamingObjectFactory.create(JndiNamingObjectFactory.java:90)
    at com.sun.enterprise.container.common.impl.ComponentEnvManagerImpl$1.create(ComponentEnvManagerImpl.java:653)
    at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:776)
    at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:744)
    at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:169)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:498)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:599)
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:470)
    at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:171)
    at org.glassfish.faces.integration.GlassFishInjectionProvider.inject(GlassFishInjectionProvider.java:184)
    at com.sun.faces.mgbean.BeanBuilder.injectResources(BeanBuilder.java:205)
    at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:103)
    at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
    at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
    at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
    at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at com.sun.faces.el.ChainTypeCompositeELResolver.getValue(ChainTypeCompositeELResolver.java:94)
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:188)
    at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:103)
    at com.sun.el.parser.AstValue.getValue(AstValue.java:179)
    at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:224)
    at org.apache.jasper.runtime.PageContextImpl.evaluateExpression(PageContextImpl.java:1009)
    at org.apache.jsp.WebPages.SearchPages.found_jsp._jspx_meth_c_forEach_0(found_jsp.java:154)
    at org.apache.jsp.WebPages.SearchPages.found_jsp._jspx_meth_f_view_0(found_jsp.java:118)
    at org.apache.jsp.WebPages.SearchPages.found_jsp._jspService(found_jsp.java:79)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
    at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:809)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:671)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:505)
    at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:476)
    at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:355)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:305)
    at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:546)
    at com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandlingStrategy.java:364)
    at com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:154)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)

我真的被卡住了,无法理解这个错误。另外,如果有人知道任何其他好的集成方式,请告诉我。我在这里跳过打印我的项目的 applictionContext.xml 和 faces-config.xml,因为我不这么认为这些文件会有问题。

编辑以包含 conf 文件

面孔-config.xml

<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"

    version="2.0">

    <application>
        <el-resolver>
            org.springframework.web.jsf.el.SpringBeanFacesELResolver
        </el-resolver>
    </application>

<managed-bean>
    <managed-bean-name>masterSearch</managed-bean-name>
        <managed-bean-class>
            com.delta.searchbeans.MasterSearch
        </managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>

<managed-bean>
    <managed-bean-name>masterSearchResult</managed-bean-name>
        <managed-bean-class>
            com.delta.resultbeans.MasterSearchResult
        </managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>

<navigation-rule>
    <description>Navigation from the MasterSearch</description>
    <from-view-id>/WebPages/MasterPage/master.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>personfound</from-outcome>
        <to-view-id>/WebPages/SearchPages/found.jsp</to-view-id>
    </navigation-case>
    <navigation-case>
        <from-outcome>personnotfound</from-outcome>
        <to-view-id>/notfound.jsp</to-view-id>
    </navigation-case>
</navigation-rule>
</faces-config>

应用程序上下文.xml

<bean id="masterSearch"
class="com.delta.searchbeans.MasterSearch">
</bean>

<context:component-scan base-package="com.delta" />
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close"
p:driverClass="com.mysql.jdbc.Driver"
p:jdbcUrl="jdbc:mysql://localhost/mydb"
p:user="root"
p:password=""
p:acquireIncrement="5"
p:idleConnectionTestPeriod="60"
p:maxPoolSize="100"
p:maxStatements="50"
p:minPoolSize="10" />
 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
          p:dataSource-ref="dataSource" />
</beans>

编辑#2

package com.delta.service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.annotation.Resource;
import javax.sql.DataSource;
import org.springframework.stereotype.Service;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.transaction.annotation.Transactional;

import com.delta.resultbeans.MasterSearchResult;


@SuppressWarnings("deprecation")
@Service("personService")
@Transactional
public class MasterSearchService {

    private SimpleJdbcTemplate jdbcTemplate;

    @Resource(name="dataSource")
     public void setDataSource(DataSource dataSource) {
         this.jdbcTemplate = new SimpleJdbcTemplate(dataSource);
     }

    public ArrayList<MasterSearchResult> getAll() {

         System.out.println("retrieving all persons ....");

          // Prepare our SQL statement
          String sql = "select id, serialnum from person";
          System.out.println("retrieving all persons ....");  
          // Maps a SQL result to a Java object
          RowMapper<MasterSearchResult> mapper = new RowMapper<MasterSearchResult>() {
                 public MasterSearchResult mapRow(ResultSet rs, int rowNum) throws SQLException {
                     System.out.println("retrieving all persons ....");
                     MasterSearchResult person = new MasterSearchResult();
                     person.setServiceNumber(rs.getString(1));
                     System.out.println("Printed by searchservice: "+rs.getString(1));
                     return person;
                 }
             };

          // Retrieve all
          return (ArrayList<MasterSearchResult>) jdbcTemplate.query(sql, mapper);
         }
}
4

2 回答 2

0

您同时声明MasterSearch为 JSF bean (in faces-context.xml) 和 Spring bean (in applicationContext.xml)。您只需要其中一个声明,因此您应该删除另一个。

  • 如果要声明MasterSearch为 JSF bean,则应使用@ManagedProperty("#{personService}")而不是@Resource(name="personService")声明对 Spring bean 的依赖。与 Spring 不同,@Resource在 JSF 中使用 JNDI 来解决依赖关系。

  • 如果你想声明MasterSearch为一个 Spring bean@Resource是可以的,但是你需要scope = "request"使它成为请求范围的。

于 2012-08-13T08:44:10.520 回答
-1

由于我看不到您的 web.xml 和 MasterSearchService 的代码(您最好将其发布),我猜可能有两个原因:

(1) 您是否在web.xml中添加了 contextConfigLocation 上下文参数?

例子:

 <context-param>
  <param-name>contextConfigLocation</param-name>
   <param-value>WEB-INF/applicationContext.xml</param-value>
 </context-param>

(2) 你有注释你的 MasterSearchService 类吗?

@Service("masterSearchService")
public class MasterSearchService {
 ....
}
于 2012-08-13T08:38:58.013 回答