职业课程 > 员工信息系统 7 章、员工信息模块的开发
客服QQ:1206116161
Xiaoxiao_0618

报错,百度了很多方法,还是不能解决

Xiaoxiao_0618 于 2018-06-20 09:31:19 发起求助
(408)
(3)
举报

这是报的错误

[org.springframework.web.context.ContextLoader]Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.handler.MappedInterceptor#1': Cannot create inner bean 'com.lxy.interceptor.SecureValidInterceptor#0' of type [com.lxy.interceptor.SecureValidInterceptor] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.lxy.interceptor.SecureValidInterceptor#0': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public com.lxy.service.ModuleService com.lxy.interceptor.SecureValidInterceptor.moduleService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lxy.service.ModuleService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4792)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5256)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1140)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1875)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.handler.MappedInterceptor#1': Cannot create inner bean 'com.lxy.interceptor.SecureValidInterceptor#0' of type [com.lxy.interceptor.SecureValidInterceptor] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.lxy.interceptor.SecureValidInterceptor#0': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public com.lxy.service.ModuleService com.lxy.interceptor.SecureValidInterceptor.moduleService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lxy.service.ModuleService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:282)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:121)
	at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:623)
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:148)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1075)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:979)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:438)
	at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1188)
	at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:277)
	at org.springframework.web.servlet.handler.AbstractHandlerMapping.detectMappedInterceptors(AbstractHandlerMapping.java:221)
	at org.springframework.web.servlet.handler.AbstractHandlerMapping.initApplicationContext(AbstractHandlerMapping.java:196)
	at org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:119)
	at org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:72)
	at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:73)
	at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:117)
	at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:92)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:396)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1505)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
	... 24 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.lxy.interceptor.SecureValidInterceptor#0': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public com.lxy.service.ModuleService com.lxy.interceptor.SecureValidInterceptor.moduleService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lxy.service.ModuleService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:271)
	... 48 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: public com.lxy.service.ModuleService com.lxy.interceptor.SecureValidInterceptor.moduleService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lxy.service.ModuleService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:517)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
	... 52 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lxy.service.ModuleService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:988)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:858)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:489)
	... 54 more
六月 20, 2018 9:29:18 上午 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.handler.MappedInterceptor#1': Cannot create inner bean 'com.lxy.interceptor.SecureValidInterceptor#0' of type [com.lxy.interceptor.SecureValidInterceptor] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.lxy.interceptor.SecureValidInterceptor#0': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public com.lxy.service.ModuleService com.lxy.interceptor.SecureValidInterceptor.moduleService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lxy.service.ModuleService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4792)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5256)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1140)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1875)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.handler.MappedInterceptor#1': Cannot create inner bean 'com.lxy.interceptor.SecureValidInterceptor#0' of type [com.lxy.interceptor.SecureValidInterceptor] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.lxy.interceptor.SecureValidInterceptor#0': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public com.lxy.service.ModuleService com.lxy.interceptor.SecureValidInterceptor.moduleService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lxy.service.ModuleService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:282)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:121)
	at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:623)
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:148)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1075)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:979)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:438)
	at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1188)
	at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:277)
	at org.springframework.web.servlet.handler.AbstractHandlerMapping.detectMappedInterceptors(AbstractHandlerMapping.java:221)
	at org.springframework.web.servlet.handler.AbstractHandlerMapping.initApplicationContext(AbstractHandlerMapping.java:196)
	at org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:119)
	at org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:72)
	at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:73)
	at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:117)
	at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:92)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:396)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1505)
	at org.springframework.beans.factory.support.AbstractAuto
wireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
	... 24 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.lxy.interceptor.SecureValidInterceptor#0': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public com.lxy.service.ModuleService com.lxy.interceptor.SecureValidInterceptor.moduleService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lxy.service.ModuleService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:271)
	... 48 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: public com.lxy.service.ModuleService com.lxy.interceptor.SecureValidInterceptor.moduleService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lxy.service.ModuleService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:517)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
	... 52 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lxy.service.ModuleService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:988)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:858)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:489)
	... 54 more

这是我的ModuleService

package com.lxy.service;

import com.lxy.constant.MethodType;
import com.lxy.support.JSONReturn;

public interface ModuleService {
	public   JSONReturn findMenu(String acctName);

	public   JSONReturn findModuleParameter(String moduleCode, String acctName);

	public   JSONReturn findBreadcrumb(String moduleCode);

	public   JSONReturn findAllModule(long roleId);

	public   JSONReturn setRoleSecureValid(long rold, String code, int type, boolean add);

	public   boolean secureValid(String userName, String[] code, MethodType type);
}

这是Spring-context的一部分


<bean id="txManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="nestedTransactionAllowed" value="true"></property>
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>
	<tx:annotation-driven transaction-manager="txManager" />

	<mvc:interceptors>
		<bean class="com.lxy.interceptor.SecureValidInterceptor"></bean>
	</mvc:interceptors>

这个是SecureValidInterceptor


package com.lxy.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.method.HandlerMethod;

import com.lxy.annotation.SecureValid;
import com.lxy.constant.LoginState;
import com.lxy.constant.SessionKey;
import com.lxy.model.Admini;
import com.lxy.service.AdminiService;
import com.lxy.service.ModuleService;
import com.lxy.support.JSONReturn;
import com.lxy.utils.CompareUtils;

import net.sf.json.JSONObject;

public class SecureValidInterceptor {
	@Autowired
	public ModuleService moduleService;
	@Autowired
	public AdminiService adminiService;

	public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handle) throws Exception {
		// TODO Auto-generated method stub

		// 为了模仿实际网络中请求的速度, 这里让每一个请求的线程都睡眠50毫秒, 项目真正上线需删除
		Thread.sleep(50);

		if (req.getRequestURI().contains("lxy/0"))
			return true;
		String userName = (String) req.getSession().getAttribute(SessionKey.MODULEACCTNAME);
		if (StringUtils.isEmpty(userName)) {
			resp.getOutputStream().print(JSONObject.fromObject(JSONReturn.buildFailure(LoginState.UNLOGIN)).toString());
			return false;
		}
		HandlerMethod handlerMethod = (HandlerMethod) handle;
		SecureValid secureValid = handlerMethod.getMethod().getAnnotation(SecureValid.class);
		if (CompareUtils.isEmpty(secureValid))
			return true;
		// 从数据库中获取当前账户是否存在, 如果不存在, 提示未登录
		Admini teAccount = adminiService.findAdminiByName(userName);
		if (CompareUtils.isEmpty(teAccount)) {
			resp.getOutputStream().print(JSONObject.fromObject(JSONReturn.buildFailure(LoginState.UNLOGIN)).toString());
			return false;
		}
		// 如果是超管, 直接通过拦截器
		if (teAccount.getAcctSuper())
			return true;
		if (!moduleService.secureValid(userName, secureValid.code(), secureValid.type())) {
			resp.getOutputStream().print(
					JSONObject.fromObject(JSONReturn.buildFailure(LoginState.PERMISSION_DENIED)).toString());
			return false;
		}
		return true;
	}
}


  • _Kiro
    _Kiro - 06月20日 (0)

    ModuleService 的实现类发出来看看,


    _Kiro
    Xiaoxiao_0618 - 06月20日 (0) @ _Kiro

    ModuleServiceImp里面的代码


    package com.lxy.service.imp;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    import org.apache.commons.collections.CollectionUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Scope;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
    
    import com.lxy.constant.LoginState;
    import com.lxy.constant.MethodType;
    import com.lxy.dao.AdminiDao;
    import com.lxy.dao.ModuleDao;
    import com.lxy.dao.RoleDao;
    import com.lxy.dao.RoleModuleDao;
    import com.lxy.dto.ModuleDto;
    import com.lxy.field.AdminiField;
    import com.lxy.field.ModuleField;
    import com.lxy.field.RoleField;
    import com.lxy.model.Admini;
    import com.lxy.model.Module;
    import com.lxy.model.Role;
    import com.lxy.model.RoleModule;
    import com.lxy.service.ModuleService;
    import com.lxy.support.JSONReturn;
    import com.lxy.utils.CompareUtils;
    
    
    @Scope
    @Service
    @Transactional(readOnly = true)
    public class ModuleServiceImp implements ModuleService {
    
    	@Autowired
    	private ModuleDao moduleDao;
    	@Autowired
    	private AdminiDao adminiDao;
    	@Autowired
    	private RoleModuleDao roleModuleDao;
    	@Autowired
    	private RoleDao roleDao;
    
    	public static final int TYPE_FIND = 1;
    	public static final int TYPE_DELETE = 2;
    	public static final int TYPE_MDOIFY = 3;
    	public static final int TYPE_ADD = 4;
    
    	
    	
    	
    	@Override
    	public JSONReturn findMenu(String acctName) {
    		// TODO Auto-generated method stub
    		Admini admini= adminiDao.findUniqueByProperty(AdminiField.ACCT_NAME, acctName);
    		if (CompareUtils.isEmpty(admini))
    			return JSONReturn.buildFailure(LoginState.UNLOGIN);
    		List<Module> moduleList = null;
    		if (admini.getAcctSuper())
    			moduleList = moduleDao.findAll();
    		else
    			moduleList = moduleDao.findMgrModule(acctName);
    		if (CollectionUtils.isEmpty(moduleList))
    			return JSONReturn.buildFailure("获取菜单失败!");
    		return JSONReturn.buildSuccess(moduleList);
    	}
    
    	@Override
    	public JSONReturn findModuleParameter(String moduleCode, String acctName) {
    		// TODO Auto-generated method stub
    		Map<String, Object> map = new HashMap<String, Object>();
    		Admini teAccount = adminiDao.findUniqueByProperty(AdminiField.ACCT_NAME, acctName);
    		if (CompareUtils.isEmpty(teAccount))
    			return JSONReturn.buildFailure(map);
    		map.put("acctount", teAccount.getAcctNickname());
    		if ("0".equals(moduleCode)) {
    			map.put("find", true);
    			map.put("add", teAccount.getAcctSuper() ? true : false);
    			map.put("del", teAccount.getAcctSuper() ? true : false);
    			map.put("modify", teAccount.getAcctSuper() ? true : false);
    			return JSONReturn.buildSuccess(map);
    		}
    		Module Module = moduleDao.findUniqueByProperty(ModuleField.MODULE_CODE, moduleCode);
    		if (CompareUtils.isEmpty(Module))
    			return JSONReturn.buildFailure("非法操作!");
    		map.put("moduleName", Module.getModuleName());
    		// 获取当前模块名与上级模块名, 前台做为面包绡显示
    		map = findModuleName(map, moduleCode, Module);
    		boolean add = false, del = false, modify = false, find = false;
    		List<RoleModule> secureValidList = roleModuleDao.findMySecureValid(findModuleArray(moduleCode), acctName);
    		if (!teAccount.getAcctSuper() && CollectionUtils.isNotEmpty(secureValidList)) {
    			for (RoleModule rm : secureValidList) {
    				if (rm.getAdds())
    					add = rm.getAdds();
    				if (rm.getDeletes())
    					del = rm.getDeletes();
    				if (rm.getModifys())
    					modify = rm.getModifys();
    				if (rm.getFinds())
    					find = rm.getFinds();
    			}
    		}
    		map.put("add", teAccount.getAcctSuper() ? true : add);
    		map.put("del", teAccount.getAcctSuper() ? true : del);
    		map.put("modify", teAccount.getAcctSuper() ? true : modify);
    		map.put("find", teAccount.getAcctSuper() ? true : find);
    		return JSONReturn.buildSuccess(map);
    	}
    
    	private String[] findModuleArray(String moduleCode) {
    		// TODO Auto-generated method stub
    		return new String[] { moduleCode };
    	}
    	//获取当前模块名称以及上级模块名称
    	private Map<String, Object> findModuleName(Map<String, Object> map, String moduleCode, Module module) {
    		// TODO Auto-generated method stub
    		module = moduleDao.findUniqueByProperty(ModuleField.MODULE_CODE, module.getModuleSuperCode());
    		if (CompareUtils.isNotEmpty(module)) {
    			map.put("superModuleName", module.getModuleName());
    			map.put("code", module.getModuleCode());
    		}
    		return map;
    	}
    	
    	@Override
    	public JSONReturn findBreadcrumb(String moduleCode) {
    		// TODO Auto-generated method stub
    		Map<String, Object> map = new HashMap<String, Object>();
    		Module module = moduleDao.findUniqueByProperty(ModuleField.MODULE_CODE, moduleCode);
    		if (CompareUtils.isEmpty(module))
    			return JSONReturn.buildFailure("ERROR");
    		Module superModule = moduleDao.findUniqueByProperty(ModuleField.MODULE_CODE, module.getModuleSuperCode());
    		if (CompareUtils.isEmpty(superModule))
    			return JSONReturn.buildFailure("ERROR");
    		map.put("superName", superModule.getModuleName());
    		map.put("name", module.getModuleName());
    		map.put("code", module.getModuleSuperCode());
    		return JSONReturn.buildSuccess(map);
    	}
    
    	@Override
    	public JSONReturn findAllModule(long roleId) {
    		// TODO Auto-generated method stub
    		Role role = roleDao.findUniqueByProperty(RoleField.ROLE_ID, roleId);
    		if (CompareUtils.isEmpty(role))
    			return JSONReturn.buildFailure("未获取到模块信息!");
    		List<Module> moduleList = moduleDao.findAll();
    		if (CollectionUtils.isEmpty(moduleList))
    			return JSONReturn.buildFailure("未获取到相关数据!");
    		List<ModuleDto> infoList = new ArrayList<ModuleDto>();
    		RoleModule tm = null;
    		for (Module mo : moduleList) {
    			ModuleDto dto = new ModuleDto();
    			dto.setId(mo.getModuleId());
    			dto.setName(mo.getModuleName());
    			dto.setCode(mo.getModuleCode());
    			dto.setSuperCode(mo.getModuleSuperCode());
    			dto.setUrl(mo.getModulePage());
    			dto.setLevel(mo.getModuleLevel());
    			tm = roleModuleDao.findByRoleLabelByModuleCode(role.getRoleLabel(), mo.getModuleCode());
    			if (CompareUtils.isNotEmpty(tm)) {
    				dto.setAdd(tm.getAdds());
    				dto.setDel(tm.getDeletes());
    				dto.setModify(tm.getModifys());
    				dto.setFind(tm.getFinds());
    			}
    			infoList.add(dto);
    		}
    		return JSONReturn.buildSuccess(infoList);
    	}
    
    	@Override
    	public JSONReturn setRoleSecureValid(long rold, String code, int type, boolean add) {
    		// TODO Auto-generated method stub
    		Module mo = moduleDao.findUniqueByProperty(ModuleField.MODULE_CODE, code);
    		if (CompareUtils.isEmpty(mo))
    			return JSONReturn.buildFailure("操作失败, 模块不存在!");
    		Role role = roleDao.findUniqueByProperty(RoleField.ROLE_ID, rold);
    		if (CompareUtils.isEmpty(role))
    			return JSONReturn.buildFailure("操作失败, 角色不存在!");
    		RoleModule rm = roleModuleDao.findByRoleLabelByModuleCode(role.getRoleLabel(), mo.getModuleCode());
    		if (CompareUtils.isEmpty(rm)) {
    			rm = new RoleModule(role.getRoleLabel(), code, mo.getModuleSuperCode(), false, false, false, false);
    			roleModuleDao.save(rm);
    		}
    		rm = setRoleSecureValid(rm, type, add);
    		return JSONReturn.buildSuccessWithEmptyBody();
    	}
    
    	private RoleModule setRoleSecureValid(RoleModule rm, int type, boolean add) {
    		// TODO Auto-generated method stub
    		return null;
    	}
    
    	@Override
    	public boolean secureValid(String userName, String[] code, MethodType type) {
    		// TODO Auto-generated method stub
    		List<RoleModule> secureValidList = roleModuleDao.findMySecureValid(code, userName);
    		if (CollectionUtils.isEmpty(secureValidList))
    			return false;
    		for (RoleModule te : secureValidList) {
    			if (type == MethodType.FIND && te.getFinds())
    				return true;
    			else if (type == MethodType.ADD && te.getAdds())
    				return true;
    			else if (type == MethodType.MODIFY && te.getModifys())
    				return true;
    			else if (type == MethodType.DELETE && te.getDeletes())
    				return true;
    		}
    		return false;
    	}
    
    }
    


  • _Kiro
    _Kiro - 06月20日 (0)

    1. 在 SecureValidInterceptor 这个类上面增加 @Component(value = "secureValidInterceptor") 注解

    2. 看看ModuleServiceImpl下面引用的那几个Dao上面有没有注解@Repository;


扫码关注TE官方微博 扫码关注TE官方微博
回复X
举报X