Hi Kristian,

I think it can not touch AppConfig instance in the constructor of HomePage
because Spring injects AppConfig into a field after create HomePage instance.

Could you try to move code in the constructor to HomePage#onInit()?

Regards,

2012/6/14 kristian_widjaja <[email protected]>:
> Hi Everyone,
>
> I am having some issue here with @Resource in a Click Page, it seems like
> the bean is not searchable nor injectable by Spring context. I suspect that
> maybe it is because I am using the AnnotationConfigWebApplicationContext
> instead of plain Spring XML context.
>
> The NullPointerException was thrown when the page get instantiated. I have
> attached the full exception and below are my codes that related to the
> initialization of web application context.
>
> --web.xml
>
>        ... [truncated for clarity]
>        <context-param>
>                <description>SpringFramework Context Annotation-based Config
> ClassLoader</description>
>                <param-name>contextClass</param-name>
>
> <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
>        </context-param>
>        <context-param>
>                <description>SpringFramework Context Annotation-based Config 
> Class
> location</description>
>                <param-name>contextConfigLocation</param-name>
>                
> <param-value>in.hitme.web.context.AppConfigurationContext</param-value>
>        </context-param>
>        <listener>
>                <description>Built-in SpringFramework Listener</description>
>
> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
>
> <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
>        </listener>
>        ... [truncated for clarity]
>        ... [truncated for clarity]
>
>        <servlet>
>                <servlet-name>springClickServlet</servlet-name>
>
> <servlet-class>org.apache.click.extras.spring.SpringClickServlet</servlet-class>
>                <load-on-startup>0</load-on-startup>
>                <init-param>
>                        <param-name>inject-page-beans</param-name>
>                        <param-value>true</param-value>
>                </init-param>
>        </servlet>
>        <servlet-mapping>
>                <servlet-name>springClickServlet</servlet-name>
>                <url-pattern>*.htm</url-pattern>
>        </servlet-mapping>
>        ... [truncated for clarity]
> </web-app>
>
> --Annotation Application Context
> @Configuration
> @ComponentScan(basePackages = { "in.hitme.web.page" }, scopeResolver =
> PageScopeResolver.class)
> @PropertySource(value = { "classpath:/config/application.properties" })
> @Import(value = { WebConfigurationContext.class,
> PersistenceConfigurationContext.class })
> public class AppConfigurationContext {
>
>    @Bean
>    public AppConfig appConfig() {
>        return new AppConfigLoader();
>    }
>
>   ... [truncated for clarity]
>
> -- Home Page
> @Component
> public class HomePage extends BasePage {
>
>    private static final long serialVersionUID = -5999383948884446789L;
>
>    @Resource(name = "appConfig")
>    private AppConfig appConfig;
>
>    public String title = PageConstants.TITLE_PAGE_HOME;
>
>    public HomePage() {
>        log.debug("AppConfig instance : " + appConfig);
>        title = appConfig.get(PageConstants.TITLE_PAGE_HOME);
>        log.debug("\n\nTitle : " + title + "\n\n");
>    }
>
>   ... [truncated for clarity]
>
> For anyone who have ever been experienced the same issue, and able to
> resolve it, kindly share the resolution. Thank you.
>
> Regards,
> Kristian Widjaja
> http://click.1134972.n2.nabble.com/file/n7578133/click-exception.txt
> click-exception.txt
>
> --
> View this message in context: 
> http://click.1134972.n2.nabble.com/Resource-not-working-when-using-Spring-3-x-AnnotationConfigWebApplicationContext-tp7578133.html
> Sent from the click-user mailing list archive at Nabble.com.



-- 
Naoki Takezoe

Reply via email to