Pages

Showing posts with label Class. Show all posts
Showing posts with label Class. Show all posts

Thursday, January 9, 2020

Autowire same bean using different Scopes in Class

Definitions in Application Context
      <bean id="RequestHit" class="com.springimplant.mvc.HitCounter" scope="request">  
           <aop:scoped-proxy/>  
      </bean>  
      <bean id="applicationHit" class="com.springimplant.mvc.HitCounter" scope="application">  
           <aop:scoped-proxy/>  
      </bean>  
      <bean id="sessionHit" class="com.springimplant.mvc.HitCounter" scope="session">  
           <aop:scoped-proxy/>  
      </bean>  
      <mvc:interceptors>  
           <mvc:interceptor>  
                <mvc:mapping path="/project/**"/>  
                <bean class="com.springimplant.mvc.interceptors.GlobalInterceptor"></bean>  
           </mvc:interceptor>  
      </mvc:interceptors>  

Defination in Class
 package com.springimplant.mvc.interceptors;  
 import java.util.Date;  
 import javax.annotation.Resource;  
 import javax.servlet.http.HttpServletRequest;  
 import javax.servlet.http.HttpServletResponse;  
 import org.springframework.beans.factory.annotation.Autowired;  
 import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;  
 import com.springimplant.mvc.HitCounter;  
 public class GlobalInterceptor extends HandlerInterceptorAdapter {  
      @Resource   
      private HitCounter RequestHit;  
      @Resource  
      private HitCounter applicationHit;  
      @Resource  
      private HitCounter sessionHit;  
      @Override  
      public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)  
                throws Exception {  
           RequestHit.setHits(RequestHit.getHits()+1);  
           System.out.println("Request Hits "+RequestHit.getHits());  
           applicationHit.setHits(applicationHit.getHits()+1);  
           System.out.println("Application Hits "+applicationHit.getHits());  
           sessionHit.setHits(sessionHit.getHits()+1);  
           System.out.println("Session Hits "+sessionHit.getHits());  
           request.setAttribute("currentDate",new Date());  
           return super.preHandle(request, response, handler);  
      }  
 }  

Sunday, November 25, 2012

PHP Fatal error: Class 'CTestCase' not found Yii

PHP Fatal error:  Class 'CTestCase' not found

Running the command from the folder where bootstarp.php for testcases resolves this issue

Try running the tests from \protected\tests

Sunday, July 8, 2012

Using Array_Filter in a class

Array_Filter does not runs directly for arrays defined as class data members.


Use the below code to filter such an array.

$fltr_instance=array_filter($array,array('className', 'callBack function defined in class'));

CakeTime Utility class/TimeHelper in Cakephp 2.0

Use CakeTime Utility class as follows
App::import("CakeTime",'utility')
Time helper no more works in controller from cakephp 2.0 onwords.

Thursday, February 24, 2011

Fatal error: Class 'Debugger' not found in when debug level set to 2 in core.php

Just started off with another RAD platform Cake PHP..and faced an issue so decided to share this fresh hard nut of my cake...

As I downloaded the version 2.0.0 of the Cake PHP RAD platform and copied it to my Apache's root...

And then there was a welcome message awaiting for me

Fatal error: Class 'Debugger' not found

I altered the Debugger value in php.ini file to 0 this problem went away..But I wanted the debugger level to be 2 so I started peeping into the websites for a solution and got a one liner

Add this:

App::import('Core', 'Debugger');

in app/config/bootstrap.php

I am still studying so will let you know more on this statement as I get back till now its a mere copy paste