Announcement Announcement Module
Collapse
No announcement yet.
BeanCreationException : Constructor threw exception; NullPointerException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • BeanCreationException : Constructor threw exception; NullPointerException

    Hi All,
    I am trying to integrate WebObjects With Spring.I Defined all the beans in applicationContext.xml file.The Thing is that Spring is unable to create Controller Bean and That Controller Is provided by WebObjects Framework.It is throwing NullPointerException and below is the Exception Message

    HTML Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRegistrationController' defined in ServletContext resource [/WEB-INF
    /applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [your.app.UserRegistrationController]: Constructor threw exception; nested exception is java.lang.NullPointerException
    below is xml file configuration
    HTML Code:
    <?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:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="http://www.springframework.org/schema/mvc 
        			       http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
                        http://www.springframework.org/schema/beans 
                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        http://www.springframework.org/schema/context 
                        http://www.springframework.org/schema/context/spring-context-3.0.xsd
                       http://www.springframework.org/schema/aop
                       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
                       http://www.springframework.org/schema/tx 
                       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">  
                       
    
    <bean name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    
    </bean>
    
    
    <!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate4.annotation.AnnotationSessionFactoryBean"> -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    		<property name="dataSource" ref="dataSource" />
    		<property name="hibernateProperties">
    			<value>
            		hibernate.dialect=org.hibernate.dialect.OracleDialect
            		hibernate.show_sql=true
            		hibernate.hbm2ddl.auto=create-drop
          		</value>
        	</property>
        	<property name="packagesToScan">
        		<list>
    		    	<value>your.app.domain</value>
         		</list>
        	</property>
        	
    	</bean>
    	<!-- <bean id="txManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="dataSource" ref="dataSource" />
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    	
      <tx:jta-transaction-manager/> 
    <tx:annotation-driven /> -->
    
    
    <!-- The DAO -->
    	<!-- Injected via @Component annotation <bean id="employeeDao" class="your.app.dao.EmployeeDaoHibernateImpl" /> 
      	<context:component-scan base-package="your.app.dao"/> -->
      	<bean id="employeeDaoHibernateImpl" class="your.app.dao.EmployeeDaoHibernateImpl">
      	</bean>
    
    <!-- The one and only SampleService -->
    	<!-- Injected via @Service annotation <bean id="sampleService" class="your.app.service.SampleServiceImpl" /> 
      	<context:component-scan base-package="your.app.service"/>-->
    
    
    <bean id="employeeServiceImpl" class="your.app.service.EmployeeServiceImpl">
    <property name="employeeDaoHibernateImpl" ref="employeeDaoHibernateImpl"/>
    </bean>
    
    <bean id="userRegistrationController" class="your.app.UserRegistrationController" >
    <property name="employeeServiceImpl" ref="employeeServiceImpl"/>
    </bean>
    
    </beans>
    UserRegistrationController.java

    HTML Code:
    public class UserRegistrationController extends ERXDirectAction {
    
    	
    	public UserRegistrationController() {
    		super(woRequest);
    		
    	}
    
    	
    
    	private EmployeeServiceImpl employeeServiceImpl;
    	
    	
    	
    	public EmployeeServiceImpl getEmployeeService() {
    		return employeeServiceImpl;
    	}
    
    	public void setEmployeeServiceImpl(EmployeeServiceImpl employeeService) {
    		this.employeeServiceImpl = employeeService;
    	}
    
    	public WOActionResults loginFormAction() {
    		NSLog.out.appendln("Calling Action::"+employeeServiceImpl);
    		return pageWithName("LoginHome");
    	}
    
    }
    I know something went Wrong with Contructor while spring trying to create instance with the help of Constructor.Any Idea whats went Wrong?

  • #2
    Have you read the stacktrace and taken a closer look at the constructor?!

    Code:
    public class UserRegistrationController extends ERXDirectAction {
    	
    	public UserRegistrationController() {
    		super(woRequest);
    		
    	}
    Where does woRequest come from?! It isn't passed into the constructor and as such isn't going to be set/available to the constructor.

    Comment


    • #3
      Hi Marten,
      Thanks for your Reply, Below Is the Full code

      added Full class Code
      <HTML>
      public class UserRegistrationController extends ERXDirectAction {

      private static WORequest woRequest;

      public UserRegistrationController() {
      super(woRequest);
      }

      private EmployeeServiceImpl employeeServiceImpl;

      public EmployeeServiceImpl getEmployeeService() {
      return employeeServiceImpl;
      }

      public void setEmployeeServiceImpl(EmployeeServiceImpl employeeService) {
      this.employeeServiceImpl = employeeService;
      }

      public WOActionResults loginFormAction() {
      NSLog.out.appendln("Calling Action::"+employeeServiceImpl);
      return pageWithName("LoginHome");
      }

      }
      </HTML>

      Comment


      • #4
        I still don't see any difference...

        Originally posted by Marten Deinum
        Where does woRequest come from?! It isn't passed into the constructor and as such isn't going to be set/available to the constructor.
        Code:
        public class UserRegistrationController extends ERXDirectAction {
        
        private static WORequest woRequest;
        
        public UserRegistrationController() {
        super(woRequest);
        }
        That (red part) is never going to be available. So it always be null....

        Comment


        • #5
          Hi Marten,
          I do agree with you ,so it is always be null but I saw in the superclass ERXDirectAction.java but in that class also they have just Declared the variable and pass it to the superclass constructor of that class(WODirectAction.java).But correct me If I am wrong.Can you tell me How I can Make it available WORequest?
          Last edited by miriyala2828; Apr 9th, 2013, 07:27 AM.

          Comment

          Working...
          X