在写flowable 工作流自定义用户组 和用户时, 重写获取用户,用户组接口时,根据网上其它人提供的代码:
import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.ManagementService;
import org.flowable.idm.api.Group;
import org.flowable.idm.api.IdmIdentityService;
import org.flowable.idm.api.User;
import org.flowable.ui.common.model.GroupRepresentation;
import org.flowable.ui.common.model.ResultListDataRepresentation;
import org.flowable.ui.common.model.UserRepresentation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
//www.1b23.com
@RestController
@RequestMapping("app")
public class UserAndGroupResourceController {
@Autowired
protected ManagementService managementService;
@Autowired
protected IdmIdentityService idmIdentityService;
@RequestMapping(value = "/rest/editor-groups", method = RequestMethod.GET)
public ResultListDataRepresentation getGroups(@RequestParam(required = false, value =
"filter") String filter) {
if (StringUtils.isNotBlank(filter)) {
filter = filter.trim();
String sql = "select * from ACT_ID_GROUP where NAME_ like #{name}";
filter = "%" + filter + "%";
List<Group> groups =
idmIdentityService.createNativeGroupQuery().sql(sql).parameter("name", filter).listPage(0, 10);
List<GroupRepresentation> result = new ArrayList<>();
for (Group group : groups) {
result.add(new GroupRepresentation(group));
}
return new ResultListDataRepresentation(result);
}
return null;
}
@RequestMapping(value = "/rest/editor-users", method = RequestMethod.GET)
public ResultListDataRepresentation getUsers(@RequestParam(value = "filter", required = false)
String filter) {
if (StringUtils.isNotBlank(filter)) {
filter = filter.trim();
String sql = "select * from ACT_ID_USER where ID_ like #{id} or LAST_ like #{name}";
filter = "%"+filter+"%";
List<User> matchingUsers =
idmIdentityService.createNativeUserQuery().sql(sql).
parameter("id",filter).parameter("name",filter).listPage(0, 10);List<UserRepresentation>
userRepresentations = new ArrayList<>(matchingUsers.size());
for (User user : matchingUsers) {
userRepresentations.add(new UserRepresentation(user));
}
return new ResultListDataRepresentation(userRepresentations);
}
return null;
}
出现报错:Consider defining a bean of type 'org.flowable.idm.api.IdmIdentityService' in your configuration.
提示我 IdmIdentityService 不能被找到,经过一番百度无果后,自己观察发现flowable的其它service 并不需要@autowired 注解:
去掉 IdmIdentityService 上的 @autowired注解后 ,就正常启动了 问题解决, 但是具体还不清楚,希望有大佬可以帮忙解释。
学习记录,不喜勿喷~