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メソッドにそれを渡します。そのメソッドは、DB から選択された値を含むリストを返します... MasterSearch.java クラスで値を取得しています。それらを印刷していますが、正常に印刷されます。そのため、そのリストをMasterSearchプロパティに割り当てます が、次のページでこのリストを取得すると、以下に示します masterSearchResultList = (ArrayList<MasterSearchResult>) personService.getAll();
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)

私は本当に立ち往生していて、このエラーを理解できません。また、統合のための他の良い方法を誰かが知っている場合は、教えてください。それらのファイルに問題があるでしょう。

編集して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>

applicationContext.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

MasterSearchJSF Bean として ( でfaces-context.xml)宣言し、Spring Bean として ( でapplicationContext.xml) 同時に宣言します。これらの宣言は 1 つしか必要ないため、別の宣言を削除する必要があります。

  • MasterSearchJSF Bean として宣言する場合は、Spring Bean への依存関係を宣言する@ManagedProperty("#{personService}")代わりに使用する必要があります。@Resource(name="personService")Spring とは異なり@Resource、JSF では JNDI を使用して依存関係を解決します。

  • MasterSearchSpring Bean として宣言する場合は問題ありませんが、リクエスト スコープにする@Resource必要があります。scope = "request"

于 2012-08-13T08:44:10.520 に答える
-1

web.xml と MasterSearchService のコードが表示されないため (投稿したほうがよいでしょう)、2 つの理由が考えられます。

(1) web.xmlに contextConfigLocation context-param を追加しましたか?

例:

 <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 に答える