NutzCN Logo
问答 shiro注入SysService接口报错
发布于 2528天前 作者 naxxm 1973 次浏览 复制 上一个帖子 下一个帖子
标签:

报错信息

2018-01-20 15:45:26 Get 'testCustomRealmMd5'<class com.naxxm.shiro.handlers.TestCustomRealmMd5>
获取主身份信息
获取认证成功后的实体信息:0001
2018-01-20 15:45:26 Get 'sysService'<interface com.naxxm.service.SysService>
2018-01-20 15:45:26 	 >> Load definition name=sysService
org.nutz.ioc.IocException: IocBean[sysService] For object [sysService] - type:[interface com.naxxm.service.SysService]
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:224)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:245)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:152)
	at com.naxxm.shiro.realms.MyRealm.doGetAuthorizationInfo(MyRealm.java:87)
	at org.apache.shiro.realm.AuthorizingRealm.getAuthorizationInfo(AuthorizingRealm.java:341)
	at org.apache.shiro.realm.AuthorizingRealm.isPermitted(AuthorizingRealm.java:462)
	at org.apache.shiro.realm.AuthorizingRealm.isPermitted(AuthorizingRealm.java:458)
	at org.apache.shiro.authz.ModularRealmAuthorizer.isPermitted(ModularRealmAuthorizer.java:223)
	at org.apache.shiro.authz.ModularRealmAuthorizer.checkPermission(ModularRealmAuthorizer.java:322)
	at org.apache.shiro.mgt.AuthorizingSecurityManager.checkPermission(AuthorizingSecurityManager.java:137)
	at org.apache.shiro.subject.support.DelegatingSubject.checkPermission(DelegatingSubject.java:205)
	at org.apache.shiro.authz.aop.PermissionAnnotationHandler.assertAuthorized(PermissionAnnotationHandler.java:74)
	at org.apache.shiro.authz.aop.AuthorizingAnnotationMethodInterceptor.assertAuthorized(AuthorizingAnnotationMethodInterceptor.java:84)
	at org.apache.shiro.authz.aop.AnnotationsAuthorizingMethodInterceptor.assertAuthorized(AnnotationsAuthorizingMethodInterceptor.java:100)
	at org.nutz.integration.shiro.NutShiroMethodInterceptor.assertAuthorized(NutShiroMethodInterceptor.java:40)
	at org.nutz.integration.shiro.NutShiroProcessor.process(NutShiroProcessor.java:120)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.nutz.ioc.ObjectLoadException: Object 'sysService' without define!
	at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:168)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:186)
	... 54 more

授权是调用

// 根据身份信息获取权限信息
		// 从数据库获取到权限数据
		List<Permission> permissionList = null;
		try {
			if (sysService == null)
				sysService = Mvcs.ctx().getDefaultIoc().get(SysService.class); // 取一次即可
			permissionList = sysService.findPermissionListByBm(activeUser.getUserBm());
			
			System.out.println("公司编码:" + activeUser.getUserBm());
			System.out.println("拥有权限:" + activeUser.getPermissions());

		
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
11 回复

没加@IocBean?

MyRealm 类


@IocBean public class MyRealm extends AuthorizingRealm { protected Dao myDao; @Inject SysService sysService; @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) {

SysService 类


``` public interface SysService { //根据用户的身份和密码 进行认证,如果认证通过,返回用户身份信息 public ActiveUser authenticat(String employeeBm,String password) throws Exception; //根据用户账号查询用户信息 public SysEmployee findEmployeeByBm(String employeeBm)throws Exception; //根据用户id查询权限范围的菜单 public List<Permission> findMenuListByBm(String employeeBm) throws Exception; //根据用户id查询权限范围的url public List<Permission> findPermissionListByBm(String employeeBm) throws Exception; }
SysServiceImpl 实现类

@IocBean
public class SysServiceImpl implements SysService {
@Inject Dao myDao;
@Override
public ActiveUser authenticat(String employeeBm, String password) throws Exception {
return null;

}

```

@wendal 加上也一样的错误信息

@IocBean(name="sysService")

加到实现类上

实现类上加了呀

接口是不是没必要加@IocBean

@wendal 完美解决,谢谢大叔~

添加回复
请先登陆
回到顶部