Announcement Announcement Module
Collapse
No announcement yet.
Help with class - org.springframework.orm.hibernate3.AnnotationSessi onFactoryBean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with class - org.springframework.orm.hibernate3.AnnotationSessi onFactoryBean

    Hi

    I am a newbie at using the Spring framework i followed an example and i am having some problems with a class in the 'applicationContext.xml' file. I created a Maven Project, i think the error is related to a jar file missing. Please if anyone can give me some help on how to remedy this error. The details of my project are listen;

    Main

    package com.apress.flexjava.usermanager.business;

    import java.util.List;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlAp plicationContext;
    import com.apress.flexjava.usermanager.dao.UserDao;
    import com.apress.flexjava.usermanager.model.User;

    public class Main {

    public static void main(String[]args){

    ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext .xml");
    UserDao userDao = (UserDao)context.getBean("userDao");
    List<User> users = userDao.findAll();
    for (User user : users){
    System.out.println(user.getForename() + " " + user.getSurname());
    }
    }

    }
    __________________________________________________ _____________________________________________
    UserDaoSpringJdbcImpl

    package com.apress.flexjava.usermanager.dao.jdbc;

    import java.util.List;
    import org.springframework.jdbc.core.simple.Parameterized BeanPropertyRowMapper;
    import org.springframework.jdbc.core.simple.SimpleJdbcDao Support;
    import com.apress.flexjava.usermanager.dao.UserDao;
    import com.apress.flexjava.usermanager.model.User;

    public class UserDaoSpringJdbcImpl extends SimpleJdbcDaoSupport implements UserDao {

    public List<User> findAll(){
    String sql = "SELECT * FROM users";
    return
    getSimpleJdbcTemplate().query(sql,ParameterizedBea nPropertyRowMapper.newInstance(User.class));
    }
    }
    __________________________________________________ ___________________________________________
    UserDao

    package com.apress.flexjava.usermanager.dao;
    import java.util.List;
    import com.apress.flexjava.usermanager.model.User;

    public interface UserDao {

    List<User> findAll();
    }
    __________________________________________________ _____________________________________________
    User

    package com.apress.flexjava.usermanager.model;

    public class User {

    private int userId;
    private String forename;
    private String surname;

    public User(){}

    public User(int userId, String forename, String surname){

    this.userId = userId;
    this.forename = forename;
    this.surname = surname;
    }

    public User(String forename, String surname){

    this.forename = forename;
    this.surname = surname;
    }

    public int getUserId(){
    return userId;

    }

    public void setUserId(int userId){

    this.userId = userId;
    }

    public String getForename(){

    return forename;
    }

    public void setForename(String forename){

    this.forename = forename;
    }

    public String getSurname(){

    return surname;
    }

    public void setSurname (String surname){

    this.surname = surname;
    }
    }
    __________________________________________________ ___________________________________________
    jdbc.properties

    jdbc.driverClassName=com.mysql.jdbc.Driver
    jdbc.url=jdbc:mysql://localhost:3306/usermanager_test
    jdbc.username=root
    jdbc.password=password
    jdbc.hibernate.dialect=org.hibernate.dialect.MySQL Dialect
    __________________________________________________ ______________________________________________
    applicationContext.xml

    <?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:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:lang="http://www.springframework.org/schema/lang"
    xmlns="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...ring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schem...ontext-2.5.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schem...ng-jee-2.5.xsd
    http://www.springframework.org/schema/lang http://www.springframework.org/schem...g-lang-2.5.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schem...ing-tx-2.5.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">

    <!-- @Required processor -->
    <bean class= "org.springframework.beans.factory.annotation.Requ iredAnnotationBeanPostProcessor"/>

    <!-- Exception translation bean post processor -->
    <bean class="org.springframework.dao.annotation.Persiste nceExceptionTranslationPostProcessor"/>

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="locations">
    <list>
    <value>classpath:jdbc.properties</value>
    </list>
    </property>
    </bean>

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name= "driverClassName"
    value= "${jdbc.driverClassName}"/>
    <property name= "url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>
    </bean>

    <bean name="userDao" class="com.apress.flexjava.usermanager.dao.jdbc.Us erDaoSpringJdbcImpl">
    <property name="dataSource" ref="dataSource"/>
    </bean>

    <!-- Hibernate SessionFactory -->

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.Annotati onSessionFactoryBean">

    <property name="dataSource" ref="dataSource"/>
    <property name="configLocation" value="classpath:hibernate.cfg.xml"/>
    <property name= "hibernateProperties" >
    <value>
    hibernate.dialect=${hibernate.dialect}
    hibernate.query.substitutions=true 'Y', false 'N'
    hibernate.cache.use_second_level_cache=true
    hibernate.hbm2ddl.auto=update
    hibernate.cache.provider_class=org.hibernate.cache .EhCacheProvider
    hibernate.use_sql comments=true
    hibernate.show_sql=true

    </value>
    </property>
    </bean>
    </beans>
    __________________________________________________ _______________________________________________
    I run the application by creating a Main class i then get the following error:

    Apr 16, 2012 5:17:10 PM org.springframework.context.support.AbstractApplic ationContext prepareRefresh
    INFO: Refreshing org.springframework.context.support.ClassPathXmlAp plicationContext@54172f: display name [org.springframework.context.support.ClassPathXmlAp plicationContext@54172f]; startup date [Mon Apr 16 17:17:10 BOT 2012]; root of context hierarchy
    Apr 16, 2012 5:17:10 PM org.springframework.beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
    Apr 16, 2012 5:17:10 PM org.springframework.context.support.AbstractApplic ationContext obtainFreshBeanFactory
    INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlAp plicationContext@54172f]: org.springframework.beans.factory.support.DefaultL istableBeanFactory@1efb836
    Apr 16, 2012 5:17:10 PM org.springframework.core.io.support.PropertiesLoad erSupport loadProperties
    INFO: Loading properties file from class path resource [jdbc.properties]
    Apr 16, 2012 5:17:10 PM org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry destroySingletons
    INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@1efb836: defining beans [org.springframework.beans.factory.annotation.Requi redAnnotationBeanPostProcessor#0,org.springframewo rk.dao.annotation.PersistenceExceptionTranslationP ostProcessor#0,propertyConfigurer,dataSource,userD ao,sessionFactory]; root of factory hierarchy
    Exception in thread "main" org.springframework.beans.factory.BeanDefinitionSt oreException: Invalid bean definition with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Could not resolve placeholder 'hibernate.dialect'
    at org.springframework.beans.factory.config.PropertyP laceholderConfigurer.processProperties(PropertyPla ceholderConfigurer.java:268)
    at org.springframework.beans.factory.config.PropertyR esourceConfigurer.postProcessBeanFactory(PropertyR esourceConfigurer.java:75)
    at org.springframework.context.support.AbstractApplic ationContext.invokeBeanFactoryPostProcessors(Abstr actApplicationContext.java:553)
    at org.springframework.context.support.AbstractApplic ationContext.invokeBeanFactoryPostProcessors(Abstr actApplicationContext.java:527)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:362)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:139)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:83)
    at com.apress.flexjava.usermanager.business.Main.main (Main.java:15)

    Attachment Attachment
    Attached Files
Working...
X