grails / grails-core

The Grails Web Application Framework
http://grails.org
Apache License 2.0
2.78k stars 951 forks source link

normal service cant be injected to gorm abstract service #11111

Open linchanghui opened 5 years ago

linchanghui commented 5 years ago

Task List

Steps to Reproduce

  1. create normal service
    
    package com.sinoregal.sonar

class CacheService implements InitializingBean{ RoleResourceRelationService roleResourceRelationService //this is gorm abstract service void testRoleResourceRelationServiceIsNull() { if(roleResourceRelationService == null) println "roleResourceRelationService in cacheService is null" else println "roleResourceRelationService in cacheService normal"

}

... }

2. create gorm service

package com.sinosonar.rbac.relation @Service(RoleResourceRelation) abstract class RoleResourceRelationService{

CacheService cacheService //this is normal grails service
void  commandPermissionCheck(int roleId, String command) {
     if(cacheService == null) println "cacheService in roleResourceRelationService is null"
     else "cacheService in roleResourceRelationService normal"
}

}

3. call roleResourceRelationService.commandPermissionCheck and cacheService.testRoleResourceRelationServiceIsNull() in any controller

### Expected Behaviour
"roleResourceRelationService normal"
"cacheService normal"

### Actual Behaviour
"roleResourceRelationService in cacheService normal"
"cacheService in roleResourceRelationService  is null"
also can set breakpoint to watch,will find the cacheService in roleResourceRelationService is null

### Environment Information
- **Groovy Version**: 2.4.15
- **Grails Version:** 3.3.5
- **JDK Version:** 1.8.0_181
- **Gradle Version:** 3.5

### Example Application

https://github.com/linchanghui/gorm-bug

### remark
i also try add @Autowired to cacheService in RoleResourceRelationService, Although it make cacheService in  roleResourceRelationService be injected
such:

@Service(RoleResourceRelation) abstract class RoleResourceRelationService{

@Autowired
CacheService cacheService

however it will result roleResourceRelationService in CacheService is null
linchanghui commented 5 years ago

add example applicaton https://github.com/linchanghui/gorm-bug