apache / apache/grails-core

normal service cant be injected to gorm abstract service

Open
#11,111 1 comment 1 reaction 0 assignees View on GitHub
info: example-attached relates-to: gorm
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

### Task List

- [x] Steps to reproduce provided
- [x] Stacktrace (if present) provided
- [x] Example that reproduces the problem uploaded to Github
- [x] Full description of the issue provided (see below)

### 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

Contributor guide

Open the contributing guide

Research direction

Start by running the linked gorm-bug example application with the stated Grails, Groovy, JDK, and Gradle versions. Inspect CacheService and RoleResourceRelationService, then reproduce the controller calls and compare injection behavior with and without @Autowired. Done means both services receive their dependencies without breaking the reverse injection.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.