-1

我有一个使用 JSF 2.0、Spring 3.0 和 Hibernate 4 的 Web 应用程序。经过两天的设置,我终于在我的数据表中得到了一个列表,但我也遇到了一个问题。我可以这么说,因为我在控制台中看到有关服务类使用的错误:

我的服务等级:

package com.ardia.service; 
@Service("compService")
@Transactional
public class ComposantImp implements ComposantService {


    @Autowired
    SessionFactory sessionFactory;


    @Override
    public void inserComposant(Composant comp) {
        // TODO Auto-generated method stub

        sessionFactory.getCurrentSession().saveOrUpdate(comp);
    }

    @Override
    public Composant getComposantById(int compId) {
        // TODO Auto-generated method stub
        return (Composant) sessionFactory.
                  getCurrentSession().
                  get(Composant.class, compId);
    }

    @Override
    public Composant getComposant(String compname) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    @SuppressWarnings("unchecked")
    public List<Composant> getComposants() {
        // TODO Auto-generated method stub
        Criteria criteria = sessionFactory.
                  getCurrentSession().
                  createCriteria(Composant.class);
                return criteria.list();
    }

}

我的豆类:

package com.ardia.beans;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import com.ardia.model.Composant;
import com.ardia.service.ComposantService;

@ManagedBean(name="userMB")
@SessionScoped
public class Composantbeam {

    @ManagedProperty(value="#{compService}")
    ComposantService service;

    private List<Composant> list;

    @PostConstruct
    public void init() {
        list=service.getComposants();
    }

    public List<Composant> getList() {
        return list;
    }

    public void setList(List<Composant> list) {
        this.list = list;
    }

    public ComposantService getService() {
        return service;
    }

    public void setService(ComposantService service) {
        this.service = service;
    }

}

我的面孔-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>
</faces-config>

我的 web.xml:

<web-app id="WebApp_ID" version="3.0"
    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-app_3_0.xsd">
    <display-name>PFE</display-name>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/application.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
    <context-param>
        <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>
    <context-param>
        <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
        <param-value>resources.application</param-value>
    </context-param>
    <listener>
        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>
    <servlet>
    <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>/Test.jsp</welcome-file>
    </welcome-file-list>
</web-app>

弹簧配置:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

       <context:component-scan base-package="ardia.beans" />
       <context:component-scan base-package="com.ardia.service" />
       <!-- Data Source Declaration -->
       <bean id="DataSource" class="org.apache.commons.dbcp.BasicDataSource" >
           <property name="driverClassName" value="org.postgresql.Driver" />
           <property name="url" value="jdbc:postgresql:PFE" />
           <property name="username" value="postgres" />
           <property name="password" value="root" />
       </bean>
       <!-- Session Factory Declaration -->
       <bean id="SessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
           <property name="dataSource" ref="DataSource" />
           <property name="packagesToScan" value="com.ardia.model" />
           <property name="hibernateProperties">
               <props>
                   <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                   <prop key="hibernate.show_sql">true</prop>
               </props>
           </property>
       </bean>
      <tx:annotation-driven transaction-manager="transactionManager"/>
     <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager" >
         <property name="sessionFactory" ref="SessionFactory"/>
     </bean>
 </beans>

我的 JSF 页面中的数据表工作并返回值列表。

但最终我得到以下错误:

avr. 21, 2013 12:41:43 PM org.apache.catalina.core.StandardContext listenerStart
Grave: Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) com.sun.faces.config.ConfigureListener
java.lang.NoClassDefFoundError: Lcom/ardia/service/ComposantService;
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Unknown Source)
    at java.lang.Class.getDeclaredFields(Unknown Source)
    at com.sun.faces.application.annotation.ManagedBeanConfigHandler.collectAnnotatedFields(ManagedBeanConfigHandler.java:242)
    at com.sun.faces.application.annotation.ManagedBeanConfigHandler.getBeanInfo(ManagedBeanConfigHandler.java:151)
    at com.sun.faces.application.annotation.ManagedBeanConfigHandler.process(ManagedBeanConfigHandler.java:137)
    at com.sun.faces.application.annotation.ManagedBeanConfigHandler.push(ManagedBeanConfigHandler.java:123)
    at com.sun.faces.application.annotation.AnnotationManager.applyConfigAnntations(AnnotationManager.java:196)
    at com.sun.faces.config.processor.AbstractConfigProcessor.processAnnotations(AbstractConfigProcessor.java:328)
    at com.sun.faces.config.processor.ManagedBeanConfigProcessor.process(ManagedBeanConfigProcessor.java:244)
    at com.sun.faces.config.processor.AbstractConfigProcessor.invokeNext(AbstractConfigProcessor.java:114)
    at com.sun.faces.config.processor.ValidatorConfigProcessor.process(ValidatorConfigProcessor.java:120)
    at com.sun.faces.config.processor.AbstractConfigProcessor.invokeNext(AbstractConfigProcessor.java:114)
    at com.sun.faces.config.processor.ConverterConfigProcessor.process(ConverterConfigProcessor.java:126)
    at com.sun.faces.config.processor.AbstractConfigProcessor.invokeNext(AbstractConfigProcessor.java:114)
    at com.sun.faces.config.processor.ComponentConfigProcessor.process(ComponentConfigProcessor.java:117)
    at com.sun.faces.config.processor.AbstractConfigProcessor.invokeNext(AbstractConfigProcessor.java:114)
    at com.sun.faces.config.processor.ApplicationConfigProcessor.process(ApplicationConfigProcessor.java:337)
    at com.sun.faces.config.processor.AbstractConfigProcessor.invokeNext(AbstractConfigProcessor.java:114)
    at com.sun.faces.config.processor.LifecycleConfigProcessor.process(LifecycleConfigProcessor.java:116)
    at com.sun.faces.config.processor.AbstractConfigProcessor.invokeNext(AbstractConfigProcessor.java:114)
    at com.sun.faces.config.processor.FactoryConfigProcessor.process(FactoryConfigProcessor.java:223)
    at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:335)
    at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:223)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4765)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5260)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1525)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1515)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.ardia.service.ComposantService
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1688)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1533)
    ... 34 more

avr. 21, 2013 12:41:43 PM org.apache.catalina.core.StandardContext startInternal
Grave: Error listenerStart
avr. 21, 2013 12:41:43 PM org.apache.catalina.core.StandardContext startInternal
Grave: Erreur de démarrage du contexte [/testefzefsdfsdfdfg] suite aux erreurs précédentes
avr. 21, 2013 12:41:43 PM org.apache.coyote.AbstractProtocol start
Infos: Starting ProtocolHandler ["http-bio-8585"]
avr. 21, 2013 12:41:43 PM org.apache.coyote.AbstractProtocol start
Infos: Starting ProtocolHandler ["ajp-bio-8010"]
avr. 21, 2013 12:41:43 PM org.apache.catalina.startup.Catalina start
Infos: Server startup in 15288 ms

我没有一个名为Lcom.ardia.service但我有一个类com.ardia.service

4

1 回答 1

-1

我从我的服务类中删除了注释。

通过 Spring 配置手动创建服务解决了我的问题。这是配置的相关部分:

<bean id="compService" class="com.ardia.service.ComposantImp">
    <property name="sessionFactory" ref="SessionFactory" />
</bean>

事实证明,JSF 和 Hibernate 不支持注释......

于 2013-04-21T11:56:32.047 回答