Re: Annotated Controller

Connor Barry <[email protected]> Sun, 16 May 2010 12:22:13 -0600
Newsgroups gmane.comp.java.springframework.user
Message-ID <[email protected]>
Why are you manually looking up a bean from the application context in a 
spring-managed bean? Just inject the APP_SERVICE_BEAN directly into your 
class. If your bean has a prototype scope and you need a new instance 
every request, then either implement the ApplicationContextAware 
interface and save the applicationContext for later use, or use method 
injection by creating a protected method called getAppServiceBean().

To get access to the ServletContext have your class implement the 
ServletContextAware interface and save it for later use.

Connor

On 5/16/2010 7:07 AM, Henry Lu wrote:
> I am trying to convert SimpleFormController to Annotated Controller
> (@Controoler). Can some one tell me how to convert the following code?
>
>      private AppService appService;
>      protected ServletContext g_application;
>
>      public void initApplicationContext()
>      {
>         WebApplicationContext wac = getWebApplicationContext();
>         this.appService = (AppService)
> wac.getBean(App_Const.APP_SERVICE_BEAN);
>         g_application = this.getServletContext();
>         g_application.removeAttribute(App_Const.APP_OBJECT);
>         g_application.setAttribute(App_Const.APP_OBJECT, "0");
>      }
>
> I do need to get WebApplicationContext and ServletContext. Is there any
> way to do the same thing like initApplicationContext()?
>
> -Henry
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> Springframework-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/springframework-user
>    

------------------------------------------------------------------------------