Merhaba Tüm spring ve hibernate ile ilgili jarlarım maven depend3ency de mevcut çalışan uygulamam ne olduysa şu hatayı veriyor java.lang.NoClassDefFoundError: Could not initialize class com.revir.util.HibernateSessionFactory

public class HibernateSessionFactory {

/** 
 * Location of hibernate.cfg.xml file.
 * Location should be on the classpath as Hibernate uses  
 * #resourceAsStream style lookup for its configuration file. 
 * The default classpath location of the hibernate config file is 
 * in the default package. Use #setConfigFile() to update 
 * the location of the configuration file for the current session.   
 */
private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
private static Configuration configuration = new Configuration();    
private static SessionFactory sessionFactory;
private static String configFile = CONFIG_FILE_LOCATION;

static {
    try {
        configuration.configure(configFile);
        sessionFactory = configuration.buildSessionFactory();
    } catch (Exception e) {
        System.err
                .println("%%%% Error Creating SessionFactory %%%%");
        e.printStackTrace();
    }
}
private HibernateSessionFactory() {
}

/**
 * Returns the ThreadLocal Session instance.  Lazy initialize
 * the <code>SessionFactory</code> if needed.
 *
 *  @return Session
 *  @throws HibernateException
 */
public static Session getSession() throws HibernateException {
    Session session = threadLocal.get();

    if (session == null || !session.isOpen()) {
        if (sessionFactory == null) {
            rebuildSessionFactory();
        }
        session = (sessionFactory != null) ? sessionFactory.openSession()
                : null;
        threadLocal.set(session);
    }

    return session;
}

/**
 *  Rebuild hibernate session factory
 *
 */
public static void rebuildSessionFactory() {
    try {
        configuration.configure(configFile);
        sessionFactory = configuration.buildSessionFactory();
    } catch (Exception e) {
        System.err
                .println("%%%% Error Creating SessionFactory %%%%");
        e.printStackTrace();
    }
}

/**
 *  Close the single hibernate session instance.
 *
 *  @throws HibernateException
 */
public static void closeSession() throws HibernateException {
    Session session = threadLocal.get();
    threadLocal.set(null);

    if (session != null) {
        session.close();
    }
}

/**
 *  return session factory
 *
 */
public static org.hibernate.SessionFactory getSessionFactory() {
    return sessionFactory;
}

/**
 *  return session factory
 *
 *  session factory will be rebuilded in the next call
 */
public static void setConfigFile(String configFile) {
    HibernateSessionFactory.configFile = configFile;
    sessionFactory = null;
}

/**
 *  return hibernate configuration
 *
 */
public static Configuration getConfiguration() {
    return configuration;
}

}

applicationcontext.xml

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

<tx:annotation-driven />
<context:component-scan
    scope-resolver="com.revir.spring.scopes.CdiScopeMetadataResolver"
    base-package="com.revir" />
<context:annotation-config />

<bean
    class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />

<security:global-method-security
    pre-post-annotations="enabled" />

</security:http>

<security:authentication-manager alias="authenticationManager">

    <security:authentication-provider
        ref="customAuthenticationProvider" />

</security:authentication-manager>

<!-- Data Source Declaration -->
<bean id="DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close">
    <property name="driverClass" value="oracle.jdbc.driver.OracleDriver" />
    <property name="jdbcUrl" value="xxxx" />
    <property name="user" value="xxxx" />
    <property name="password" value="xxxx" />
    <property name="maxPoolSize" value="10" />
    <property name="maxStatements" value="0" />
    <property name="minPoolSize" value="5" />
</bean>

<!-- Session Factory Declaration -->
<bean id="SessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="DataSource" />
    <property name="annotatedClasses">
        <list>
            <value>com.xxx.xxxx</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property>
</bean>

<!-- Enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="transactionManager" />

<!-- Transaction Manager is defined -->
<bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="SessionFactory" />
</bean>

<!-- User DAO Declaration -->
<bean id="KisiDAO" class="com.revir.domain.KisiDAO">
    <property name="sessionFactory" ref="SessionFactory" />
</bean>

<bean id="KisiadresiDAO" class="com.revir.domain.KisiadresiDAO">
    <property name="sessionFactory" ref="SessionFactory" />
</bean>

<bean id="AdresDAO" class="com.revir.domain.AdresDAO">
    <property name="sessionFactory" ref="SessionFactory" />
</bean>

<bean id="BaseHibernateDAO" class="com.revir.domain.BaseHibernateDAO">
</bean>

<!-- Beans Declaration -->
<bean id="Kisi" class="com.revir.domain.Kisi" />
<bean id="KisiBean" class="com.revir.managed.bean.UserBean" />
<bean id="KisiB" class="com.revir.managed.bean.KisiBean" />
<bean id="LoginController" class="com.revir.controller.LoginController" />
<bean name="messageSource"
    class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename">
        <value>mymessages</value>
    </property>
</bean>
<bean id="localeResolver"
    class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
    <property name="defaultLocale" value="tr_TR" />
</bean>

<bean id="accessDeniedHandler" class="com.revir.handler.MyAccessDeniedHandler">
    <property name="accessDeniedUrl" value="/REVIR/accessdenied.xhtml" />
</bean>

<bean id="loginfailedHandler" class="com.revir.handler.AuthentificationListener">
    <property name="loginFailedUrl" value="/REVIR/loginfailed.xhtml" />
</bean>
<bean id="KisiDataModel" class="com.revir.managed.bean.KisiDataModel" />
<bean id="customAuthenticationProvider" class="com.revir.util.CustomAuthenticationProvider" />
<bean id="KpLogin" class="com.revir.domain.KpLogin" />
<bean id="KpLoginDAO" class="com.revir.domain.KpLoginDAO" />

</beans>

soruldu: 14 May '14, 01:44

burakh79's gravatar image

burakh79
1446
cevap kabul oranı: 0%

1

Spring ve Hibernate versiyonlarını güncelledim sorun çözüldü

(14 May '14, 03:06) burakh79 burakh79's gravatar image
Bu soruya ilk cevap veren sen ol!
toggle preview

powered by BitNami OSQA