Question: I'm using zf2 apigility in my web application. With production mode, if `config_cache_enabled` is `true` in `config/application.config.php`, I get this message error when requesting `access_token`:

> 
> The storage configuration for OAuth2 is missing
> 
> 
> 

If I set it to `false`, I get my access token.

So my problem is to have `config_cache_enabled` set to `true` and a successful request for getting the access token in production mode, due to best performance when configuration is cached. How to do that ?

This is my `zf-mvc-auth` configuration :

```
'zf-mvc-auth' => array(
        'authentication' => array(
            'adapters' => array(
                'CustomStorage' => array(
                    'adapter' => 'ZF\\MvcAuth\\Authentication\\OAuth2Adapter',
                    'storage' => array(
                        'storage' => 'Application\\Adapter\\OAuth\\CustomPdoAdapter',
                        'route' => '/oauth',
                    ),
                ),
            ),
        ),
    ),

```

This is my oauth2.local.php :

```
'zf-oauth2' => array(
        'db' => array(
            'dsn'      => 'mysql:dbname=mydatabase;host=localhost',
            'username' => 'root',
            'password' => '',
        ),
        'allow_implicit' => true,
        'access_lifetime' => 3600,
        'enforce_state'  => true,
        'storage'        => 'Application\Adapter\OAuth\CustomPdoAdapter',
        'storage_settings' => array(
           'user_table' => 'users',
        ),
         'options' => array(
            'always_issue_new_refresh_token' => true,
        ),
    ),

```

I think it is well configured.

Answer: 
You **can't** exclude specifically Controller actions and you **can't** exclude by class name either (using the `doNotApplyToClassNames` property) because the rule is applied by file level and not class.

The closest I could get was to exclude the whole Controller from the rule like this:

```
NoDef.doNotApplyToFilesMatching = /.*Controller.groovy/

```

I also recommend excluding `Services` and `grailsApplication` injection from the rule, as it doesn't bother me to have defs there. For example:

```
class SomeService {
    def otherService
    def grailsApplication
}

```

The rule configuration for this should be:

```
NoDef.excludeRegex = /(.+Service|.+Controller|grailsApplication)/

```
If you are using codenarc plugin then I believe you should be able to disable some of the rules in codenarc rule set file as mentioned in this blog

<http://www.tothenew.com/blog/grails-clean-code-configure-codenarc-plugin/>