You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@click.apache.org by iida <ii...@gmail.com> on 2011/02/09 07:25:57 UTC

Using Spring PageScopeResolver, NullpointerException

Hi all,
Calling NullpointerException index will be generated.
"echo TestService + + +" want to get.

Click2.3.0-RC1 is used.

I hope that someone can help me.
Thanks

--index.java
package jp.test;
public class index extends Page {

    @Resource(name="tService")
    private TestService tService;

    public String stest= "test";

    public index(){
        stest = tService.getTestMessage();
    }
}
--

--TestService.java
package jp.service;
@Component
public class TestService {

    public String getTestMessage() {
        return "echo TestService+++";
    }
}

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

    <context:component-scan base-package="jp"
scope-resolver="org.apache.click.extras.spring.PageScopeResolver"/>

</beans:beans>
--

[Click] [error] handleException: java.lang.RuntimeException:
java.lang.NullPointerException
at org.apache.click.ClickServlet.initPage(ClickServlet.java:1317)
at org.apache.click.ClickServlet.createPage(ClickServlet.java:1103)
at org.apache.click.ClickServlet.handleRequest(ClickServlet.java:367)
at org.apache.click.ClickServlet.doGet(ClickServlet.java:276)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:861)
at
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1584)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NullPointerException
at jp.test.Index.<init>(Index.java:24)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at
org.apache.click.extras.spring.SpringClickServlet.newPageInstance(SpringClickServlet.java:449)
at org.apache.click.ClickServlet.initPage(ClickServlet.java:1257)
... 17 more

Re: Using Spring PageScopeResolver, NullpointerException

Posted by iida <ii...@gmail.com>.
I have changed.
Change tested OK.

thanks
--
@Component
public class Index extends Page {

    @Resource(name="testService")
    private TestService testService;

    private String stes="initdat";
    private String title="title";

    public Index(){
        //When you set here, nested error.
    }

    public void onGet(){
        stes = "onGet:" + testService.getTestMessage();
        System.out.println(stes);
    }

    public void onRender(){
        stes = "onRender:" + testService.getTestMessage();
        System.out.println(stes);
    }

    public void onInit(){
        stes = "onInit:" + testService.getTestMessage();
        System.out.println(stes);
        addModel("stes",stes);
    }

}

2011/2/9 tomasz bandura <to...@gmail.com>

> I modified a little your example ( for spring 3.0 but it shouldn't any
> meaning)
>
>

Re: Using Spring PageScopeResolver, NullpointerException

Posted by tomasz bandura <to...@gmail.com>.
I modified a little your example ( for spring 3.0 but it shouldn't any
meaning)


package jp.test;
*@Component*
public class index extends Page {

    @Resource(name="tService")
    private TestService tService;

    public String stest= "test";

    public *void onInit*(){
        stest = tService.getTestMessage();
    }
}

and it works

T.


2011/2/9 iida <ii...@gmail.com>

> Hi tomasz bandura,
>
> org.springframework changed the TRACE.
> 'registered' but no, I do not know what to do.
>
> iida
> --
> [DEBUG] [o.s.b.f.s.DefaultListableBeanFactory]  Creating shared instance of
> singleton bean 'testService'
> [DEBUG] [o.s.b.f.s.DefaultListableBeanFactory]  Creating instance of bean
> 'testService'
> [DEBUG] [o.s.b.f.s.DefaultListableBeanFactory]  Eagerly caching bean
> 'testService' to allow for resolving potential circular references
> [TRACE] [o.s.b.CachedIntrospectionResults]  Getting BeanInfo for class
> [jp.service.TestService]
> [TRACE] [o.s.b.CachedIntrospectionResults]  Caching PropertyDescriptors for
> class [jp.service.TestService]
> [TRACE] [o.s.b.CachedIntrospectionResults]  Found bean property 'class' of
> type [java.lang.Class]
> [TRACE] [o.s.b.CachedIntrospectionResults]  Found bean property
> 'testMessage' of type [java.lang.String]
> [DEBUG] [o.s.b.f.s.DefaultListableBeanFactory]  Finished creating instance
> of bean 'testService'
> [DEBUG] [o.s.b.f.s.DefaultListableBeanFactory]  Returning cached instance
> of singleton bean
> 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
> [DEBUG] [o.s.b.f.s.DefaultListableBeanFactory]  Returning cached instance
> of singleton bean
> 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
> [DEBUG] [o.s.b.f.s.DefaultListableBeanFactory]  Returning cached instance
> of singleton bean
> 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
> [TRACE] [o.s.w.c.s.XmlWebApplicationContext]  Publishing event in context
> [org.springframework.web.context.support.XmlWebApplicationContext@b60b93]:
> org.springframework.context.event.ContextRefreshedEvent[source=org.springframework.web.context.support.XmlWebApplicationContext@b60b93:
> display name [Root WebApplicationContext]; startup date [Wed Feb 09 17:33:32
> JST 2011]; root of context hierarchy]
> [DEBUG] [o.s.w.c.ContextLoader]  Published root WebApplicationContext as
> ServletContext attribute with name
> [org.springframework.web.context.WebApplicationContext.ROOT]
> [INFO ] [o.s.w.c.ContextLoader]  Root WebApplicationContext: initialization
> completed in 1953 ms
> [Click] [info ] ***  Initializing Click 2.3.0-RC1 in trace mode  ***
> [Click] [info ] initialized LogService:
> org.apache.click.service.ConsoleLogService
>
>
>
>
> 2011/2/9 tomasz bandura <to...@gmail.com>
>
> Hi,
>>
>> At the beginning, please try to change in logging.properties level to INFO
>> to be sure that your beans are already 'registered' in Spring context
>>
>> t.
>>
>>
>>

Re: Using Spring PageScopeResolver, NullpointerException

Posted by iida <ii...@gmail.com>.
Hi tomasz bandura,

org.springframework changed the TRACE.
'registered' but no, I do not know what to do.

iida
--
[DEBUG] [o.s.b.f.s.DefaultListableBeanFactory]  Creating shared instance of
singleton bean 'testService'
[DEBUG] [o.s.b.f.s.DefaultListableBeanFactory]  Creating instance of bean
'testService'
[DEBUG] [o.s.b.f.s.DefaultListableBeanFactory]  Eagerly caching bean
'testService' to allow for resolving potential circular references
[TRACE] [o.s.b.CachedIntrospectionResults]  Getting BeanInfo for class
[jp.service.TestService]
[TRACE] [o.s.b.CachedIntrospectionResults]  Caching PropertyDescriptors for
class [jp.service.TestService]
[TRACE] [o.s.b.CachedIntrospectionResults]  Found bean property 'class' of
type [java.lang.Class]
[TRACE] [o.s.b.CachedIntrospectionResults]  Found bean property
'testMessage' of type [java.lang.String]
[DEBUG] [o.s.b.f.s.DefaultListableBeanFactory]  Finished creating instance
of bean 'testService'
[DEBUG] [o.s.b.f.s.DefaultListableBeanFactory]  Returning cached instance of
singleton bean
'org.springframework.context.annotation.internalCommonAnnotationProcessor'
[DEBUG] [o.s.b.f.s.DefaultListableBeanFactory]  Returning cached instance of
singleton bean
'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
[DEBUG] [o.s.b.f.s.DefaultListableBeanFactory]  Returning cached instance of
singleton bean
'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
[TRACE] [o.s.w.c.s.XmlWebApplicationContext]  Publishing event in context
[org.springframework.web.context.support.XmlWebApplicationContext@b60b93]:
org.springframework.context.event.ContextRefreshedEvent[source=org.springframework.web.context.support.XmlWebApplicationContext@b60b93:
display name [Root WebApplicationContext]; startup date [Wed Feb 09 17:33:32
JST 2011]; root of context hierarchy]
[DEBUG] [o.s.w.c.ContextLoader]  Published root WebApplicationContext as
ServletContext attribute with name
[org.springframework.web.context.WebApplicationContext.ROOT]
[INFO ] [o.s.w.c.ContextLoader]  Root WebApplicationContext: initialization
completed in 1953 ms
[Click] [info ] ***  Initializing Click 2.3.0-RC1 in trace mode  ***
[Click] [info ] initialized LogService:
org.apache.click.service.ConsoleLogService




2011/2/9 tomasz bandura <to...@gmail.com>

> Hi,
>
> At the beginning, please try to change in logging.properties level to INFO
> to be sure that your beans are already 'registered' in Spring context
>
> t.
>
>
>

Re: Using Spring PageScopeResolver, NullpointerException

Posted by tomasz bandura <to...@gmail.com>.
Hi,

At the beginning, please try to change in logging.properties level to INFO to
be sure that your beans are already 'registered' in Spring context

t.

2011/2/9 iida <ii...@gmail.com>

> Hi all,
> Calling NullpointerException index will be generated.
> "echo TestService + + +" want to get.
>
> Click2.3.0-RC1 is used.
>
> I hope that someone can help me.
> Thanks
>
> --index.java
> package jp.test;
> public class index extends Page {
>
>     @Resource(name="tService")
>     private TestService tService;
>
>     public String stest= "test";
>
>     public index(){
>         stest = tService.getTestMessage();
>     }
> }
> --
>
> --TestService.java
> package jp.service;
> @Component
> public class TestService {
>
>     public String getTestMessage() {
>         return "echo TestService+++";
>     }
> }
>
> --spring-beans.xml
> <beans:beans
>   xmlns:beans="http://www.springframework.org/schema/beans"
>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>   xmlns:context="http://www.springframework.org/schema/context"
>   xsi:schemaLocation="http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>      http://www.springframework.org/schema/context
> http://www.springframework.org/schema/context/spring-context-2.5.xsd">
>
>     <context:component-scan base-package="jp"
> scope-resolver="org.apache.click.extras.spring.PageScopeResolver"/>
>
> </beans:beans>
> --
>
> [Click] [error] handleException: java.lang.RuntimeException:
> java.lang.NullPointerException
> at org.apache.click.ClickServlet.initPage(ClickServlet.java:1317)
>  at org.apache.click.ClickServlet.createPage(ClickServlet.java:1103)
> at org.apache.click.ClickServlet.handleRequest(ClickServlet.java:367)
>  at org.apache.click.ClickServlet.doGet(ClickServlet.java:276)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
>  at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
> at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
>  at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
> at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
>  at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
> at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
>  at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
> at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
>  at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
> at
> org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:861)
>  at
> org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
> at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1584)
>  at java.lang.Thread.run(Thread.java:662)
> Caused by: java.lang.NullPointerException
> at jp.test.Index.<init>(Index.java:24)
>  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>  at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
> at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>  at java.lang.Class.newInstance0(Class.java:355)
> at java.lang.Class.newInstance(Class.java:308)
>  at
> org.apache.click.extras.spring.SpringClickServlet.newPageInstance(SpringClickServlet.java:449)
> at org.apache.click.ClickServlet.initPage(ClickServlet.java:1257)
>  ... 17 more
>
>