Announcement Announcement Module
Collapse
No announcement yet.
@Autowired not working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Autowired not working

    my dispatcher-servlet.xml is
    <?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="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schem...ontext-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    <mvc:annotation-driven />
    <context:component-scan base-package="com.controllers" />
    <bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver" >
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlVi ew" />
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
    </bean>

    <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/sravan"/>
    <property name="username" value="root"/>
    <property name="password" value="root"/>
    </bean>
    <bean class="org.springframework.web.servlet.mvc.annotat ion.DefaultAnnotationHandlerMapping" >
    <property name="order"><value>1</value></property>
    <property name="interceptors">
    <list>
    <ref bean="themeChangeInterceptor" />
    <ref bean="localeChangeInterceptor" />
    </list>
    </property>


    </bean>

    <bean class="org.springframework.web.servlet.mvc.annotat ion.AnnotationMethodHandlerAdapter" />

    <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotati on.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="myDataSource" />
    <property name="annotatedClasses">
    <list>
    <value>com.beans.Contact</value>
    <value>com.beans.Upload</value>
    <value>com.beans.ContactPerson</value>
    <value>com.beans.Sequence</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.hbm2ddl.auto">update</prop>
    </props>
    </property>
    </bean>
    <bean id="validator" class="com.validator.ContactFormValidator" >
    <property name="sessionFactory" ref="mySessionFactory"></property>
    </bean>
    <bean id="contactsDAO" class="com.dao.ContactsDAO">
    <property name="sessionFactory" ref="mySessionFactory"></property>
    </bean>
    <bean id="task" class="com.schedule.SyncWorker" />
    <bean name="jobDetailBean" class="org.springframework.scheduling.quartz.JobDe tailBean" p:jobClass="com.schedule.CustomJob" >
    <property name="jobDataAsMap">
    <map>
    <entry key="worker" >
    <ref bean="task" />
    </entry>
    </map>
    </property>
    </bean>
    <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronT riggerBean" p:jobDetail-ref="jobDetailBean" p:startDelay="10000" p:cronExpression="0/10 * * * * ?" />
    <bean class="org.springframework.scheduling.quartz.Sched ulerFactoryBean" p:waitForJobsToCompleteOnShutdown="true" >
    <property name="triggers">
    <list>
    <ref bean="cronTrigger" />
    </list>
    </property>
    </bean>
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.C ommonsMultipartResolver">
    <property name="maxUploadSize" value="100000"/>
    </bean>
    <bean id="themeSource"
    class="org.springframework.ui.context.support.Reso urceBundleThemeSource">
    <property name="basenamePrefix" value="theme-" />
    </bean>
    <bean id="themeChangeInterceptor"
    class="com.themes.ThemeChange">
    <property name="paramName" value="theme" />
    </bean>
    <bean id="themeResolver"
    class="com.themes.ThemeResolver">
    <property name="defaultThemeName" value="default" />
    </bean>
    <bean id="localeChangeInterceptor"
    class="org.springframework.web.servlet.i18n.Locale ChangeInterceptor">
    <property name="paramName" value="lang" />
    </bean>
    <bean id="localeResolver"
    class="org.springframework.web.servlet.i18n.Cookie LocaleResolver">
    <property name="defaultLocale" value="en"/>
    </bean>
    <bean id="messageSource"
    class="org.springframework.context.support.Reloada bleResourceBundleMessageSource">
    <property name="basename" value="classpath:messages" />
    <property name="defaultEncoding" value="UTF-8"/>
    </bean>
    </beans>




    and i created a class for generating sequence number. and the class is

    package com.generator;

    import java.io.Serializable;

    import org.hibernate.HibernateException;
    import org.hibernate.SessionFactory;
    import org.hibernate.engine.SessionImplementor;
    import org.hibernate.id.IdentifierGenerator;
    import org.springframework.beans.factory.annotation.Autow ired;

    import com.beans.Sequence;

    public class CustomerId implements IdentifierGenerator {
    @Autowired
    private SessionFactory mySessionFactory;
    int number=0;
    public Serializable generate(SessionImplementor arg0, Object arg1)throws HibernateException {
    // TODO Auto-generated method stub
    Sequence sequence=null;
    System.out.println("sessionFactory "+mySessionFactory);
    sequence = (Sequence)mySessionFactory.openSession().get(Seque nce.class,"Contact");
    int lastNo=sequence.getLastNo();
    System.out.println("lastNo "+lastNo);
    sequence.setLastNo(lastNo+1);
    mySessionFactory.openSession().update(sequence);
    return lastNo;

    }

    }

    and when run this application mySessionFactory is showing as null.

    Please help me.
    thanx in advance.
Working...
X