javax.annotation.Resource的Resource注解为什么可以取到spring声明的bean呢?

如题,我一直以为spring是把bean维护在自己的容器里,但是为什么这个javax的注解也能用呢?

2个回答

@Resource是jdk自身的注解,在JSR-250规范中,本身只是一个注解。spring只是对@Resource做了支持,让它在spring框架中也生效

u010224911
靑雨 明白了!
大约一年之前 回复

Spring将@Resource注解的name属性解析为bean的 根据名称去获取的啊自动注入 Spring支持该注解的注入。

u010224911
靑雨 你的意思是,@Resource能够取到spring声明的bean是spring去操控的而不是java自己操控的吗? 虽然是java的类。
大约一年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Spring 下bean的注入,注解注入时运行测试类出错javax.annotation.ManagedBean' found and supported for component scanning
十一月 21, 2019 1:46:01 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh 信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@5679c6c6: startup date [Thu Nov 21 13:46:01 CST 2019]; root of context hierarchy 十一月 21, 2019 1:46:01 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definitions from class path resource [com/sun/annotation/applicationContext.xml] 十一月 21, 2019 1:46:01 下午 org.springframework.context.annotation.ClassPathBeanDefinitionScanner registerDefaultFilters 信息: JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
用ssh全注解时,在@Action中@Result注解报错
import javax.annotation.Resource; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Namespace; import org.apache.struts2.convention.annotation.ParentPackage; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import com.biz.ICrmBiz; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven; import com.pojo.SysUser; @SuppressWarnings("serial") @Controller @Namespace("/") @ParentPackage("struts-default") @Scope("prototype") public class CrmAction extends ActionSupport implements ModelDriven<Object> { private ICrmBiz ermBiz; @Action(value="/querySysUserById",results={@Result(name="success",location="/left.jsp")}) public String querySysUserById() { SysUser sysUser=null; sysUser=ermBiz.querySysUserById(1); return SUCCESS; } ![图片说明](https://img-ask.csdn.net/upload/201510/04/1443922259_210946.png)
ssm框架使用了注解为什么识别不了
错误:Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.censoft.iic.webmagic.ptpeye.PTPEyePageProcessor] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, lookup=, authenticationType=CONTAINER)} ![图片说明](https://img-ask.csdn.net/upload/201706/16/1497605124_363642.png)
使用webmagic爬数据,将现在的项目加入后Tomcat就出现问题,求大神指教啊!!!
使用ssm框架,已经进行了注解 Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.censoft.iic.webmagic.pteye.PTPEyePageProcessor] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, lookup=, authenticationType=CONTAINER)}
Spring 注入错误,求解
以前我们的项目就一个单独的项目文件,现在需要把项目拆分,于是我就想把bean dao service抽出来做成jar包来导入到拆分后的各个项目中,但是出现了问题 我们的项目是使用struts2+Spring+Hibernate,使用了Spring的注解,现报错如下. [code="java"] [2011-01-07 16:36:04,346]-INFO (JCLLoggerAdapter.java:262)|schema update complete [2011-01-07 16:36:05,786]-INFO (JCLLoggerAdapter.java:262)|closing [2011-01-07 16:36:05,847]-ERROR (ContextLoader.java:220)|Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'newsAction': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'newsServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.fohome.front.dao.NewsDao] 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), @javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)} at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:300) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:987) at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:909) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:495) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1206) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:314) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) at org.apache.catalina.core.StandardHost.start(StandardHost.java:722) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:516) at org.apache.catalina.core.StandardServer.start(StandardServer.java:710) at org.apache.catalina.startup.Catalina.start(Catalina.java:583) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'newsServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.fohome.front.dao.NewsDao] 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), @javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)} at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:300) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:435) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:409) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:541) at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:297) ... 37 more Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.fohome.front.dao.NewsDao] 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), @javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:903) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:772) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:686) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:431) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:409) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:541) at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:297) ... 50 more 2011-1-7 16:36:05 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 'newsAction': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'newsServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.fohome.front.dao.NewsDao] 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), @javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)} at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:300) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:987) at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:909) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:495) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1206) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:314) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) at org.apache.catalina.core.StandardHost.start(StandardHost.java:722) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:516) at org.apache.catalina.core.StandardServer.start(StandardServer.java:710) at org.apache.catalina.startup.Catalina.start(Catalina.java:583) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'newsServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.fohome.front.dao.NewsDao] 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), @javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)} at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:300) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:435) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:409) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:541) at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:297) ... 37 more Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.fohome.front.dao.NewsDao] 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), @javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:903) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:772) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:686) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:431) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:409) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:541) at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:297) ... 50 more 2011-1-7 16:36:05 org.apache.catalina.core.StandardContext start 严重: Error listenerStart 2011-1-7 16:36:05 org.apache.catalina.core.StandardContext start 严重: Context [/Fohome] startup failed due to previous errors 2011-1-7 16:36:05 org.apache.catalina.core.ApplicationContext log [/code] 百思不得其解,求各位高手相救
Spring无法获取ApplicationContext上下文对象怎么解决?
涉及到的类包括: 1. ITestService.java 2. TestServiceImp.java 3. autoWiringService.java 以及Spring配置文件: 4.autoWiring.xml 对应的源码为: 1. ITestService.java ``` package com.z.test.annotation; /** * Created by Z on 2016/11/16. */ public interface ITestService { public void annoTest(); } ``` 2.TestServiceImp.java ``` package com.z.test.annotation; import org.springframework.stereotype.Service; /** * Created by Z on 2016/11/16. * 如何引入注解 */ @Service("testServiceImp") public class TestServiceImp implements ITestService { public void annoTest(){ System.out.println("注解调用"); } } ``` 3.autoWiringService.java ``` package com.z.test.annotation; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import javax.annotation.Resource; /** * Created by Z on 2016/11/16. */ public class AutoWiringService { @Resource(name ="testServiceImp") public ITestService iTestService; public void autoTest(){ iTestService.annoTest(); } public static void main(String[] args){ ApplicationContext context =new ClassPathXmlApplicationContext("autowiring.xml"); AutoWiringService autoW=(AutoWiringService)context.getBean("autoWiringService"); autoW.autoTest(); } } ``` 使用了@Service 和 @Resource注解。目录结构: ![图片说明](https://img-ask.csdn.net/upload/201611/17/1479358416_204200.png) 在AutoWiringService运行主方法进行测试时,总是有错误如下: ![图片说明](https://img-ask.csdn.net/upload/201611/17/1479358474_121304.png) 猜测是否是无法读取xml文件?还是哪里没有配置好?
配置文件出错
org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.itime.dao.FamilyDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)} application里面用的是注解的方式 高手们来尽快解决!!!!!!
struts2和spring3整合后,为什么找不到action了
想用spring来管理struts2的action,因为还要向action中注入service,但用@Controller("/roleList")注解后,却找不到action了,这是为何喃? import javax.annotation.Resource; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.InterceptorRef; import org.apache.struts2.convention.annotation.ParentPackage; import org.apache.struts2.convention.annotation.Result; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import com.xxx.action.BaseAction; import com.xxx.common.bean.PaginationReturnBean; import com.xxx.common.constant.ConstantDefine; import com.xxx.common.security.Description; import com.xxx.common.security.Privilege; import com.xxx.manage.bean.RoleQueryBean; import com.xxx.manage.entity.Role; import com.bizex.manage.service.RoleService; import com.opensymphony.xwork2.ModelDriven; @Controller("/roleList") @Scope("prototype") @ParentPackage("manage") @InterceptorRef("manageStack") public class RoleListAction extends BaseAction implements ModelDriven<RoleQueryBean> { @Resource(name = "roleService") private RoleService roleService; private static final long serialVersionUID = -3029290129233743984L; private RoleQueryBean roleQueryBean = new RoleQueryBean(); private PaginationReturnBean<Role> roles = new PaginationReturnBean<Role>();// 查询角色列表的输出 @Action(results={@Result(location="manage/role_list.jsp")}) public String execute() throws Exception { roles = roleService.getRoleList(roleQueryBean); return SUCCESS; } public RoleQueryBean getModel() { return roleQueryBean; } public PaginationReturnBean<Role> getRoles() { return roles; } public void setRoles(PaginationReturnBean<Role> roles) { this.roles = roles; } }
注入资源依赖关系失败
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'paiMaiSerDaoImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.dlsp.service.PaiMaiSerDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)} at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:306) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1122) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626) 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:4842) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5303) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.dlsp.service.PaiMaiSerDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:986) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:856) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:768) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:438) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:416) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:550) at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:150) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:303) ... 22 more 二月 24, 2017 11:03:25 上午 org.apache.catalina.core.StandardContext startInternal 严重: One or more listeners failed to start. Full details will be found in the appropriate container log file 二月 24, 2017 11:03:25 上午 org.apache.catalina.core.StandardContext startInternal 严重: Context [/ZuoYeXiangMu_3] startup failed due to previous errors 二月 24, 2017 11:03:25 上午 org.apache.catalina.core.ApplicationContext log 信息: Closing Spring root WebApplicationContext 二月 24, 2017 11:03:25 上午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc 警告: The web application [ZuoYeXiangMu_3] registered the JDBC driver [oracle.jdbc.OracleDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. 二月 24, 2017 11:03:25 上午 org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks 严重: The web application [ZuoYeXiangMu_3] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@41376b06]) and a value of type [java.lang.Class] (value [class oracle.sql.AnyDataFactory]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 二月 24, 2017 11:03:25 上午 org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks 严重: The web application [ZuoYeXiangMu_3] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@7b5d1ae6]) and a value of type [java.lang.Class] (value [class oracle.sql.TypeDescriptorFactory]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 二月 24, 2017 11:03:25 上午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["http-nio-8080"] 二月 24, 2017 11:03:25 上午 org.apache.coyote.AbstractProtocol start 信息: Starting ProtocolHandler ["ajp-nio-8009"] 二月 24, 2017 11:03:25 上午 org.apache.catalina.startup.Catalina start 信息: Server startup in 4212 ms package com.dlsp.controller; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.PrintWriter; import java.util.List; import java.util.Random; import javax.annotation.Resource; import javax.imageio.ImageIO; import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import javax.servlet.jsp.PageContext; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import com.dlsp.dao.UserLoginDao; import com.dlsp.domain.Manage; import com.dlsp.domain.Saleinfo; import com.dlsp.service.PaiMaiSerDao; import com.dlsp.service.UserLoginSerDao; import com.dlsp.service.impl.PaiMaiSerDaoImpl; import com.sun.java.swing.plaf.motif.resources.motif; import com.sun.org.apache.regexp.internal.recompile; @Controller public class PaiMaicontroler { @Resource private PaiMaiSerDao paimai; //获得随机颜色 Color getRandColor(int fc, int bc){ Random random = new Random(); if (fc > 255) fc = 255; if (bc > 255) bc = 255; int r = fc + random.nextInt(bc - fc); int g = fc + random.nextInt(bc - fc); int b = fc + random.nextInt(bc - fc); return new Color(r, g, b); } //验证码 @RequestMapping("yanzheng.action") public void yanzhengn(HttpServletRequest request,HttpServletResponse response,HttpSession session){ //设置页面不缓存 session=request.getSession(); response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); // 在内存中创建图象 int width = 60, height = 20; BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // 获取图形上下文 Graphics g = image.getGraphics(); //生成随机类 Random random = new Random(); // 设定背景色 g.setColor(getRandColor(200, 250)); g.fillRect(0, 0, width, height); //设定字体 g.setFont(new Font("Times New Roman", Font.PLAIN, 18)); //画边框 //g.setColor(new Color()); //g.drawRect(0,0,width-1,height-1); // 随机产生155条干扰线,使图象中的认证码不易被其它程序探测到 g.setColor(getRandColor(160, 200)); for (int i = 0; i < 155; i++) { int x = random.nextInt(width); int y = random.nextInt(height); int xl = random.nextInt(12); int yl = random.nextInt(12); g.drawLine(x, y, x + xl, y + yl); } // 取随机产生的认证码(4位数字) String sRand = ""; for (int i = 0; i < 4; i++) { String rand = String.valueOf(random.nextInt(10)); sRand += rand; // 将认证码显示到图象中 g.setColor(new Color(20 + random.nextInt(110), 20 + random .nextInt(110), 20 + random.nextInt(110)));//调用函数出来的颜色相同,可能是因为种子太接近,所以只能直接生成 g.drawString(rand, 13 * i + 6, 16); } // 将认证码存入SESSION session.setAttribute("numrand", sRand); // 图象生效 g.dispose(); // 输出图象到页面 try { ImageIO.write(image, "JPEG", response.getOutputStream()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //out.clear(); //out = PageContext.pushBody(); } @RequestMapping("saleinfo.action") public String getsuoyou(Model mo) { List<Saleinfo> jihe = paimai.getall(); mo.addAttribute("jihe", jihe); return "saleinfo"; } @RequestMapping("addinfo.action") public String addinfo(Saleinfo sale, Model mo) { if (paimai.insertsale(sale) > 0) { mo.addAttribute("cheng", 1); } else { mo.addAttribute("cheng", 2); } return "redirect:saleinfo.action"; } @RequestMapping("update.action") public String updateinfo(Saleinfo sale,Model mo){ if (paimai.updatedale(sale)>0) { mo.addAttribute("gai", 1); }else{ mo.addAttribute("gai", 2); } return "redirect:saleinfo.action"; } @RequestMapping("sahn.action") public String deleteinfo(int id,Model mo){ if (paimai.deletesale(id)>0) { mo.addAttribute("shan", 1); }else{ mo.addAttribute("shan", 2); } return "redirect:saleinfo.action"; } } package com.dlsp.controller; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.PrintWriter; import java.util.List; import java.util.Random; import javax.annotation.Resource; import javax.imageio.ImageIO; import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import javax.servlet.jsp.PageContext; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import com.dlsp.dao.UserLoginDao; import com.dlsp.domain.Manage; import com.dlsp.domain.Saleinfo; import com.dlsp.service.PaiMaiSerDao; import com.dlsp.service.UserLoginSerDao; import com.dlsp.service.impl.PaiMaiSerDaoImpl; import com.sun.java.swing.plaf.motif.resources.motif; import com.sun.org.apache.regexp.internal.recompile; @Controller public class PaiMaicontroler { @Resource private PaiMaiSerDao paimai; //获得随机颜色 Color getRandColor(int fc, int bc){ Random random = new Random(); if (fc > 255) fc = 255; if (bc > 255) bc = 255; int r = fc + random.nextInt(bc - fc); int g = fc + random.nextInt(bc - fc); int b = fc + random.nextInt(bc - fc); return new Color(r, g, b); } //验证码 @RequestMapping("yanzheng.action") public void yanzhengn(HttpServletRequest request,HttpServletResponse response,HttpSession session){ //设置页面不缓存 session=request.getSession(); response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); // 在内存中创建图象 int width = 60, height = 20; BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // 获取图形上下文 Graphics g = image.getGraphics(); //生成随机类 Random random = new Random(); // 设定背景色 g.setColor(getRandColor(200, 250)); g.fillRect(0, 0, width, height); //设定字体 g.setFont(new Font("Times New Roman", Font.PLAIN, 18)); //画边框 //g.setColor(new Color()); //g.drawRect(0,0,width-1,height-1); // 随机产生155条干扰线,使图象中的认证码不易被其它程序探测到 g.setColor(getRandColor(160, 200)); for (int i = 0; i < 155; i++) { int x = random.nextInt(width); int y = random.nextInt(height); int xl = random.nextInt(12); int yl = random.nextInt(12); g.drawLine(x, y, x + xl, y + yl); } // 取随机产生的认证码(4位数字) String sRand = ""; for (int i = 0; i < 4; i++) { String rand = String.valueOf(random.nextInt(10)); sRand += rand; // 将认证码显示到图象中 g.setColor(new Color(20 + random.nextInt(110), 20 + random .nextInt(110), 20 + random.nextInt(110)));//调用函数出来的颜色相同,可能是因为种子太接近,所以只能直接生成 g.drawString(rand, 13 * i + 6, 16); } // 将认证码存入SESSION session.setAttribute("numrand", sRand); // 图象生效 g.dispose(); // 输出图象到页面 try { ImageIO.write(image, "JPEG", response.getOutputStream()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //out.clear(); //out = PageContext.pushBody(); } @RequestMapping("saleinfo.action") public String getsuoyou(Model mo) { List<Saleinfo> jihe = paimai.getall(); mo.addAttribute("jihe", jihe); return "saleinfo"; } @RequestMapping("addinfo.action") public String addinfo(Saleinfo sale, Model mo) { if (paimai.insertsale(sale) > 0) { mo.addAttribute("cheng", 1); } else { mo.addAttribute("cheng", 2); } return "redirect:saleinfo.action"; } @RequestMapping("update.action") public String updateinfo(Saleinfo sale,Model mo){ if (paimai.updatedale(sale)>0) { mo.addAttribute("gai", 1); }else{ mo.addAttribute("gai", 2); } return "redirect:saleinfo.action"; } @RequestMapping("sahn.action") public String deleteinfo(int id,Model mo){ if (paimai.deletesale(id)>0) { mo.addAttribute("shan", 1); }else{ mo.addAttribute("shan", 2); } return "redirect:saleinfo.action"; } } package com.dlsp.controller; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.PrintWriter; import java.util.List; import java.util.Random; import javax.annotation.Resource; import javax.imageio.ImageIO; import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import javax.servlet.jsp.PageContext; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import com.dlsp.dao.UserLoginDao; import com.dlsp.domain.Manage; import com.dlsp.domain.Saleinfo; import com.dlsp.service.PaiMaiSerDao; import com.dlsp.service.UserLoginSerDao; import com.dlsp.service.impl.PaiMaiSerDaoImpl; import com.dlsp.service.impl.UserLoginService; import com.sun.java.swing.plaf.motif.resources.motif; import com.sun.org.apache.regexp.internal.recompile; @Controller public class UserLogincontroler { @Resource private UserLoginSerDao login; @RequestMapping("admin.action") public String asdsa(){ return "admin"; } //普通登陆判断 @RequestMapping("dengdeng.action") public String denglu(Manage ma,Model mo,String checkbox){ ma=login.loginman(ma); if (!ma.equals("")) { if (ma.getAdmin()==1) { mo.addAttribute("user", ma); if (!checkbox.equals("")) { Cookie co=new Cookie("username", ma.getManame()); } return "saleinfo"; } return "admin"; } return "admin"; } //转换管理员登陆界面 @RequestMapping("denglu.action") public String denglupan(Model mo){ mo.addAttribute("admin", "123123"); return "admin"; } //转换普通用户登陆界面 @RequestMapping("dengluq.action") public String denglupantwo(Model mo){ mo.addAttribute("admin", null); return "admin"; } } package com.dlsp.controller; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.PrintWriter; import java.util.List; import java.util.Random; import javax.annotation.Resource; import javax.imageio.ImageIO; import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import javax.servlet.jsp.PageContext; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import com.dlsp.dao.UserLoginDao; import com.dlsp.domain.Manage; import com.dlsp.domain.Saleinfo; import com.dlsp.service.PaiMaiSerDao; import com.dlsp.service.UserLoginSerDao; import com.dlsp.service.impl.PaiMaiSerDaoImpl; import com.dlsp.service.impl.UserLoginService; import com.sun.java.swing.plaf.motif.resources.motif; import com.sun.org.apache.regexp.internal.recompile; @Controller public class UserLogincontroler { @Resource private UserLoginSerDao login; @RequestMapping("admin.action") public String asdsa(){ return "admin"; } //普通登陆判断 @RequestMapping("dengdeng.action") public String denglu(Manage ma,Model mo,String checkbox){ ma=login.loginman(ma); if (!ma.equals("")) { if (ma.getAdmin()==1) { mo.addAttribute("user", ma); if (!checkbox.equals("")) { Cookie co=new Cookie("username", ma.getManame()); } return "saleinfo"; } return "admin"; } return "admin"; } //转换管理员登陆界面 @RequestMapping("denglu.action") public String denglupan(Model mo){ mo.addAttribute("admin", "123123"); return "admin"; } //转换普通用户登陆界面 @RequestMapping("dengluq.action") public String denglupantwo(Model mo){ mo.addAttribute("admin", null); return "admin"; } } <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.dlsp.dao.PaiMaiDao"> <sql id="sale"> said,saname,startmoney,endmondey,starttime,endtime,panduan,remark </sql> <sql id="man"> id,maname,password,cardnum,tell, dizhi,youzheng,admin </sql> <!-- 基本的用户信息 --> <resultMap id="paimaiMP" type="com.dlsp.domain.Saleinfo"> <id property="said" column="said" /> <result property="saname" column="saname" /> <result property="startmoney" column="startmoney" /> <result property="endmondey" column="endmondey" /> <result property="starttime" column="starttime" /> <result property="endtime" column="endtime" /> <result property="panduan" column="panduan" /> <result property="remark" column="remark" /> </resultMap> <resultMap type="com.dlsp.domain.Manage" id="manageMP"> <id property="id" column="id" /> <result property="maname" column="maname" /> <result property="password" column="password" /> <result property="cardnum" column="cardnum" /> <result property="tell" column="tell" /> <result property="dizhi" column="dizhi" /> <result property="youzheng" column="youzheng" /> <result property="admin" column="admin" /> </resultMap> <select id="getall" resultMap="paimaiMP" > select <include refid="sale"/> from saleinfo </select> <select id="loginman" resultMap="manageMP"> select <include refid="man"/> from manage </select> </mapper> <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.dlsp.dao.UserLoginDao"> <sql id="man"> id,maname,password,cardnum,tell, dizhi,youzheng,admin </sql> <resultMap type="com.dlsp.domain.Manage" id="manageMP"> <id property="id" column="id" /> <result property="maname" column="maname" /> <result property="password" column="password" /> <result property="cardnum" column="cardnum" /> <result property="tell" column="tell" /> <result property="dizhi" column="dizhi" /> <result property="youzheng" column="youzheng" /> <result property="admin" column="admin" /> </resultMap> <select id="loginman" parameterType="com.dlsp.domain.Manage" resultType="com.dlsp.domain.Manage"> select <include refid="man"/> from manage where maname=#{maname} and password=#{password} </select> </mapper> package com.dlsp.service; import java.util.List; import com.dlsp.domain.Manage; import com.dlsp.domain.Saleinfo; public interface PaiMaiSerDao { //查 List<Saleinfo> getall(); //增 int insertsale(Saleinfo sale); //删 int deletesale(int id); //改 int updatedale(Saleinfo sale); } package com.dlsp.service; import com.dlsp.domain.Manage; public interface UserLoginSerDao { //登陆 Manage loginman(Manage manage); } package com.dlsp.service.impl; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Service; import com.dlsp.dao.PaiMaiDao; import com.dlsp.domain.Manage; import com.dlsp.domain.Saleinfo; import com.dlsp.service.PaiMaiSerDao; @Service public class PaiMaiSerDaoImpl implements PaiMaiSerDao {// 设置依赖的类 @Resource private PaiMaiSerDao dao; @Override public List<Saleinfo> getall() { return dao.getall(); } @Override public int insertsale(Saleinfo sale) { return dao.insertsale(sale); } @Override public int deletesale(int id) { return dao.deletesale(id); } @Override public int updatedale(Saleinfo sale) { return dao.updatedale(sale); } } package com.dlsp.service.impl; import javax.annotation.Resource; import org.springframework.stereotype.Service; import com.dlsp.dao.PaiMaiDao; import com.dlsp.dao.UserLoginDao; import com.dlsp.domain.Manage; import com.dlsp.service.UserLoginSerDao; @Service public class UserLoginService implements UserLoginSerDao { @Resource private UserLoginSerDao dao; @Override public Manage loginman(Manage manage) { return dao.loginman(manage); } } <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd" > <!-- 1.包扫描 service dao (注解方式) --> <context:component-scan base-package="com.dlsp.dao,com.dlsp.service"/> <!-- 2. jdbc.properties 属性配置文件 --> <context:property-placeholder location="classpath:jdbc.properties"/> <!-- 3.数据源 --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${jdbc.driverclass}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> </bean> <!-- 4.sqlsessionfactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <!-- 怎么和mybatis整合,关联Mybatis,关联映射文件 --> <property name="configLocation" value="classpath:sqlMapConfig.xml"/> <property name="mapperLocations" value="classpath:com/dlsp/dao/*.xml"/> </bean> <!-- 5.事务 --> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED"/> <tx:method name="add*" propagation="REQUIRED"/> <tx:method name="insert*" propagation="REQUIRED"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="delete*" propagation="REQUIRED"/> <tx:method name="find*" read-only="true"/> <tx:method name="get*" read-only="true"/> <tx:method name="list*" read-only="true"/> <tx:method name="*" read-only="true"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut expression="execution(* com.dlsp.service.*.*(..))" id="txPointCut"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointCut"/> </aop:config> </beans>
service利用注解注入,会空指针异常。而用getBean方式则可以获取到service。
**spring配置文件如下:** <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <bean id="placeholderProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:conf/config.properties</value> </list> </property> <property name="fileEncoding" value="utf-8" /> </bean> <import resource="spring-hibernate.xml" /> <!-- Import basic SpringMVC Resteasy integration --> <import resource="classpath:springmvc-resteasy.xml" /> <!-- 扫描文件 --> <context:component-scan base-package="com.sinopec.carlife" /> </beans> **service接口如下:** package com.sinopec.carlife.service.api; import java.util.List; import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import com.sinopec.carlife.model.Region; @Path("/regions") @Consumes({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON}) public interface RegionService { /** * 获取所有城市 * @return * @throws Exception */ @POST @Path("/all") public List<Region> findRegions() throws Exception; } **service实现类如下:** package com.sinopec.carlife.service.impl; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.sinopec.carlife.dao.RegionDAO; import com.sinopec.carlife.model.Region; import com.sinopec.carlife.service.api.RegionService; @Service("regionService") public class RegionServiceImpl implements RegionService { @Autowired private RegionDAO regionDAO; @Override public List<Region> findRegions() throws Exception { return regionDAO.findRegions(); } } **junit测试如下:** package test.com.sinopec.carlife; import java.util.List; import javax.annotation.Resource; import junit.framework.TestCase; import org.junit.Test; import com.sinopec.carlife.model.Region; import com.sinopec.carlife.service.api.RegionService; public class RegionServiceTest extends TestCase { @Resource(name="regionService") private RegionService regionService; @Test public void testFindRegions() { try { /*ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/spring.xml"); regionService = (RegionService) context.getBean("regionService");*/ List<Region> regions = regionService.findRegions(); System.out.println(regions.size()); } catch (Exception e) { e.printStackTrace(); } } }
错误资源注入依赖失败,ssm框架整合,求大神来看,谢谢
ssm框架我也算是比较熟悉了,刚开始接触那会到是报过注入失败的错,当时都很快解决了,这次的就是找不到原因,用的注解注入,请大神帮忙看下,谢谢谢谢. 报错信息如下: 警告: Exception encountered during context initialization - cancelling refresh attempt org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tbItemController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.taotao.service.TbItemService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(mappedName=, shareable=true, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER, lookup=)}
ssh注解,获取不到server。
web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>sshTest1</display-name> <!-- 配置Spring的监听器,用于初始化ApplicationContext对象 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext*.xml</param-value> </context-param> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> <!-- 自动扫描action --> <init-param> <param-name>actionPackages</param-name> <param-value>com.lovo</param-value> </init-param> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>login.jsp</welcome-file> </welcome-file-list> </web-app> applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd "> <!--建立数据源 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <!-- SQL Server数据驱动 --> <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"> </property> <!-- 数据库地址 --> <property name="url" value="jdbc:sqlserver://localhost:1433; DatabaseName=sshTest"> </property> <property name="username" value="sa"></property> <property name="password" value="123"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <!--配置Hibernate的方言--> <prop key="hibernate.dialect"> org.hibernate.dialect.SQLServerDialect </prop> <!--格式化输出sql语句--> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.use_sql_comments">false</prop> </props> </property> <!--自动扫描实体 --> <property name="packagesToScan" value="com.lovo.*" /> </bean> <!-- 使用 annotation --> <context:annotation-config /> <!-- 自动扫描与装配bean --> <context:component-scan base-package="com.lovo"></context:component-scan> <!-- 采用注释的方式配置 aop --> <aop:aspectj-autoproxy /> <!-- 用注解来实现事务管理 --> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <tx:annotation-driven transaction-manager="txManager"/> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="select*" read-only="true"/> <tx:method name="get*" read-only="true"/> <tx:method name="load*" read-only="true"/> <tx:method name="find*" read-only="true"/> <tx:method name="query*" read-only="true"/> <tx:method name="read*" read-only="true"/> <tx:method name="sync*"/> <tx:method name="*" propagation="REQUIRED" rollback-for="Exception"/> </tx:attributes> </tx:advice> </beans> struts.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <!-- 开启使用开发模式,详细错误提示 --> <constant name="struts.devMode" value="true" /> <!-- 将对象交给spring管理 --> <constant name="struts.objectFactory" value="spring" /> <!-- 指定资源编码类型 --> <constant name="struts.i18n.encoding" value="UTF-8" /> <!-- 指定每次请求到达,重新加载资源文件 --> <constant name="struts.i18n.reload" value="false" /> <!-- 指定每次配置文件更改后,自动重新加载 --> <constant name="struts.configuration.xml.reload" value="false" /> <!-- 默认后缀名 --> <constant name="struts.action.extension" value="action," /> </struts> action package com.lovo.action; import javax.annotation.Resource; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Namespace; import org.apache.struts2.convention.annotation.ParentPackage; import org.apache.struts2.convention.annotation.Result; import org.springframework.stereotype.Controller; import com.lovo.bean.Emp; import com.lovo.service.EmpService; import com.opensymphony.xwork2.ActionSupport; @Namespace("/") @ParentPackage("struts-default") @Controller public class EmpAction extends ActionSupport { @Resource() public Emp emp ; private EmpService empService ; @ Action(value = "empAction", results = { @Result(name = "success", location = "/index.jsp"), @Result(name = "index", location = "/login.jsp")}) public String add() { try { empService.add(emp); } catch (Exception e) { e.printStackTrace(); return "index"; } return "success"; } public Emp getEmp() { return emp; } public void setEmp(Emp emp) { this.emp = emp; } public EmpService getEmpService() { return empService; } public void setEmpService(EmpService empService) { this.empService = empService; } } bean package com.lovo.bean; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @Entity(name="t_emp") public class Emp implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; @Column(name = "pk_name") private String name; @Column(name = "fk_age") private int age; public Emp(){} public Emp(int id, String name, int age) { super(); this.id = id; this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } } dao package com.lovo.dao; import java.util.List; import javax.annotation.Resource; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Repository; import com.lovo.bean.Emp; @Repository("empDao") public class EmpDao { @Resource(name="sessionFactory") private SessionFactory sessionFactory; public void add(Emp emp){ Session session = sessionFactory.getCurrentSession(); session.save(emp); } public List findAll(){ return null; } public SessionFactory getSessionFactory() { return sessionFactory; } public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } } package com.lovo.service; import javax.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.lovo.bean.Emp; import com.lovo.dao.EmpDao; @Service("empService") @Transactional public class EmpService { @Resource(name="empDao") private EmpDao empDao; public EmpService(){} public void add(Emp emp) { empDao.add(emp); } public EmpDao getEmpDao() { return empDao; } public void setEmpDao(EmpDao empDao) { this.empDao = empDao; } } action 访问server的时候,没有访问到server获取数据报空指针异常。 高手帮我看看哪里错了。 。。
注解注入报错,困扰几天了,求大神指教
springMVC整合mybatis的时候报错:HTTP Status 500 - Servlet.init() for servlet springmvc threw exception type Exception report message Servlet.init() for servlet springmvc threw exception description The server encountered an internal error that prevented it from fulfilling this request. exception javax.servlet.ServletException: Servlet.init() for servlet springmvc threw exception org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2549) org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2538) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:748) root cause org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [mapper.UserMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)} org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:306) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:647) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:598) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:661) org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:517) org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:458) org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:138) javax.servlet.GenericServlet.init(GenericServlet.java:158) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2549) org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2538) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:748) root cause org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [mapper.UserMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)} org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:924) org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:793) org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707) org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:438) org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:416) org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:549) org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:150) org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:303) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:647) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:598) org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:661) org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:517) org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:458) org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:138) javax.servlet.GenericServlet.init(GenericServlet.java:158) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2549) org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2538) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:748) 到底是哪里的问题啊,求指教,已经困扰好多天了
我的spring mvc注解失败了,求大神回答啊,谢谢了
严重: Servlet /SurperseShake threw load() exception org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [gth.surpriseshake.services.TbSysuserMapperService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER, lookup=)} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1103) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:963) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:858) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:442) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:420) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:545) at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:155) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:305) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672) at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543) at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484) at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) at javax.servlet.GenericServlet.init(GenericServlet.java:212) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4187) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4496) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1041) at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:964) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) at org.apache.catalina.core.StandardHost.start(StandardHost.java:785) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:519) at org.apache.catalina.core.StandardServer.start(StandardServer.java:710) at org.apache.catalina.startup.Catalina.start(Catalina.java:581) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
spring+mybatis中注解Controller时,启动时会报错,求大神帮忙,很急!
* org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hotelManageController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.jianpai.vegetablecalf.service.indent.IndentService] found for dependency [com.jianpai.vegetablecalf.service.indent.IndentService]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(mappedName=, shareable=true, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER, lookup=)} * at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:321) * at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) * at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) * at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) * at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) * at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) * at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) * at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) * at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:776) * at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861) * at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) * at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444) * at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326) * at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) * at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5099) * at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5615) * at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) * at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899) * at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875) * at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652) * at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1260) * at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:2002) * at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) * at java.util.concurrent.FutureTask.run(FutureTask.java:262) * at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) * at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) * at java.lang.Thread.run(Thread.java:745) * Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.jianpai.vegetablecalf.service.indent.IndentService] found for dependency [com.jianpai.vegetablecalf.service.indent.IndentService]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(mappedName=, shareable=true, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER, lookup=)} *
SpringMVC3.2+hibernate4.2.5 多数据库注解 找不到实体问题
下面我只粘主要的配置文件和实体 applicationContext.xml <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:hsm-db-dchsqlserver.properties</value> <value>classpath:hsm-db-drhsqlserver.properties</value> </list> </property> </bean> <import resource="db-dch.xml" /> <import resource="db-drh.xml" /> 资源文件就不贴了,资源文件主要配置数据库驱动连接等相关配置 db-dch.xml ![图片说明](https://img-ask.csdn.net/upload/201501/08/1420683458_426800.png) ![图片说明](https://img-ask.csdn.net/upload/201501/08/1420683433_468361.png) ![图片说明](https://img-ask.csdn.net/upload/201501/08/1420683482_414961.png) db-drh.xml ![图片说明](https://img-ask.csdn.net/upload/201501/08/1420683619_647886.png) ![图片说明](https://img-ask.csdn.net/upload/201501/08/1420683631_436180.png) ![图片说明](https://img-ask.csdn.net/upload/201501/08/1420683683_883648.png) 两个数据库都有一个Employee的表,所以这里我分开两个实体 DCHEmployeeEntity ![图片说明](https://img-ask.csdn.net/upload/201501/08/1420683700_464099.png) DRHEmployeeEntity ![图片说明](https://img-ask.csdn.net/upload/201501/08/1420683710_847204.png) DAO也分两个 DCHEmployeeDAO ![图片说明](https://img-ask.csdn.net/upload/201501/08/1420683694_848628.png) DRHEmployeeDAO ![图片说明](https://img-ask.csdn.net/upload/201501/08/1420683747_220630.png) 目录结构 ![图片说明](https://img-ask.csdn.net/upload/201501/08/1420683756_255356.png) 控制类,项目访问 import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import com.dch.projects.dch.employee.entity.DCHEmployeeEntity; import com.dch.projects.dch.employee.service.IDCHEmployeeService; import com.dch.projects.drh.employee.entity.DRHEmployeeEntity; import com.dch.projects.drh.employee.service.IDRHEmployeeService; import com.dch.projects.oms.user.entity.UserEntity; import com.dch.projects.oms.user.service.IUserService; @Controller @RequestMapping("/") public class IndexController { @Autowired private IUserService userService; @Autowired private IDCHEmployeeService dchEmployeeService; @Autowired private IDRHEmployeeService drhEmployeeService; @RequestMapping("/main") public ModelAndView main(HttpServletRequest request) { List<UserEntity> listUsers=this.userService.getAllUsersByHql("from UserEntity"); for(UserEntity user:listUsers){ System.out.println(user.getName()); } List<DCHEmployeeEntity> listDCHEmployees=this.dchEmployeeService.getAllDCHEmployeesByHql("from DCHEmployeeEntity"); for(DCHEmployeeEntity employee:listDCHEmployees){ System.out.println("德诚行:"+employee.getEmpNo()+" "+employee.getEmpName()); } List<DRHEmployeeEntity> listDRHEmployees=this.drhEmployeeService.getAllDRHEmployeesByHql("from DRHEmployeeEntity"); for(DRHEmployeeEntity employee:listDRHEmployees){ System.out.println("德瑞行:"+employee.getEmpNo()+" "+employee.getEmpName()); } return new ModelAndView("index/main"); } } 后台错误 ![图片说明](https://img-ask.csdn.net/upload/201501/08/1420683806_403295.png) ![图片说明](https://img-ask.csdn.net/upload/201501/08/1420683774_999026.png) 页面错误,都一样 ![图片说明](https://img-ask.csdn.net/upload/201501/08/1420683824_221980.png) DCHEmployee这个能查出数据,就是DRHEmployee报错,配置那里看来看去都没什么问题,除了table的名字是一样,但如果我使用hibernate配置文件配置实体而不用注解的话是没问题,使用注解就出现这问题。 哪位大神帮看下问题出在哪里,谢谢了。
spring+mybatis中,我的Controller只要加上注解就会报这个错误,紧急求救~!
``` org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hotelManageController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.jianpai.vegetablecalf.service.indent.IndentService] found for dependency [com.jianpai.vegetablecalf.service.indent.IndentService]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(mappedName=, shareable=true, description=, name=, type=class java.lang.Object, lookup=, authenticationType=CONTAINER)} at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:321) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:776) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5099) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5615) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1260) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:2002) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) ``` ``` ```
spring aspect中的around和transactionManager的问题求解
问题出现的情况是这样的,首先我在xml里面启用了事务注解 <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> 然后再另一个类中配置了切面 package test.ssh.advice; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import org.springframework.stereotype.Component; @Component @Aspect public class XMLAspect { @Pointcut("execution(public * test.ssh.service.*.*(..))") public void pointCutService(){} @Before("pointCutService()") public void before(){ System.out.println("before start"); } @After("pointCutService()") public void after(){ System.out.println("after start"); } @AfterReturning("pointCutService()") public void afterReturning(){ System.out.println(" afterReturning start"); } @AfterThrowing("pointCutService()") public void throwAble(){ System.out.println(" throwAble start"); } @Around("pointCutService()") public void around(ProceedingJoinPoint pjp) throws Throwable{ System.out.println("around start"); pjp.proceed(); System.out.println("around end"); } } 接着我对数据库中的一条记录进行查询,奇怪的是在方法内部是查询出来了数据,但是当我把这条数据返回出去的时候发生了奇怪的事情,我在外面吧返回出去的值打印出来居然是null。代码如下 测试代码: public static void main(String[] args) throws SQLException { ApplicationContext springContext = new ClassPathXmlApplicationContext("annotationBeans.xml"); User user = (User) springContext.getBean("user"); user.setName("test1"); System.out.println("check "+userServiceInter.select(user)); System.out.println(userServiceInter.query()); } 输出结果如下: 23:55:24,639 INFO SchemaUpdate:182 - HHH000228: Running hbm2ddl schema update 23:55:24,641 INFO SchemaUpdate:193 - HHH000102: Fetching database metadata 23:55:24,644 INFO SchemaUpdate:205 - HHH000396: Updating schema 23:55:24,692 INFO TableMetadata:65 - HHH000261: Table found: mytest.table_user 23:55:24,692 INFO TableMetadata:66 - HHH000037: Columns: [id, name] 23:55:24,692 INFO TableMetadata:68 - HHH000108: Foreign keys: [] 23:55:24,693 INFO TableMetadata:69 - HHH000126: Indexes: [primary] 23:55:24,694 INFO SchemaUpdate:240 - HHH000232: Schema update complete Methodstart around start before start Hibernate: select user0_.id as id0_, user0_.name as name0_ from table_user user0_ where user0_.name=? id 44 name test1 around end after start afterReturning start method returning check null Methodstart around start before start around end after start afterReturning start method returning null service类的代码: package test.ssh.service; import javax.annotation.Resource; import org.hibernate.SessionFactory; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import test.ssh.demo.User; import test.ssh.inter.UserServiceInter; @Component @Transactional public class UserService implements UserServiceInter{ private SessionFactory sessionFactory; @Resource public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } @Override public void save(User user) { sessionFactory.getCurrentSession().save(user); } @Override public void delete(User user) { // TODO Auto-generated method stub } @Override public void update(User user) { System.out.println(user.getName()+"is saving"); } @Override public User select(User user) { String hql="from User where name = ?"; user = (User) sessionFactory.getCurrentSession().createQuery(hql).setString(0, user.getName()).uniqueResult(); System.out.println("id "+user.getId()+" name "+user.getName()); User test = new User(); test.setId(user.getId()); test.setName(user.getName()); return user; } @Override public User query() { // TODO Auto-generated method stub return new User(); } } 非常奇怪,我试着直接返回一个new出来的对象居然也是null。 经过一番折腾,怀疑是spring的申明式事务和我申明的切面冲突了。将around注释掉就可以正常返回结果。虽然说问题得到解决了 不过还是想知道为什么会这样。我看视频上不是说切面可以在切入点随意的添加逻辑的而不影响方法本身的执行么,如果这样的话就不应该会返回null阿。
SSB框架 mapper 注入时报错
这个项目是基于servlet开发的项目,现有的spring 和mybatis 现在想引入springMVC,controller,service两个在一起测试挺好的,但是链接上mapper(我这里没有DAO,mapper.java ---mapper.xml),但是在service @Auto.. 或者是@Resource都会报错, org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'planController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.zcloudMVC.service.TestService com.zcloudMVC.controller.PlanController.testService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.zcloudMVC.mapper.TestMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER, lookup=)} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) ~[spring-context-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[spring-context-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:663) [spring-webmvc-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:629) [spring-webmvc-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:677) [spring-webmvc-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:548) [spring-webmvc-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:489) [spring-webmvc-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) [spring-webmvc-4.1.3.RELEASE.jar:4.1.3.RELEASE] at javax.servlet.GenericServlet.init(GenericServlet.java:241) [servlet-api-2.5-20081211.jar:na] at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:431) [jetty-6.1.19.jar:6.1.19] at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263) [jetty-6.1.19.jar:6.1.19] at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) [jetty-util-6.1.19.jar:6.1.19] at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:676) [jetty-6.1.19.jar:6.1.19] at org.mortbay.jetty.servlet.Context.startContext(Context.java:140) [jetty-6.1.19.jar:6.1.19] at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1239) [jetty-6.1.19.jar:6.1.19] at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517) [jetty-6.1.19.jar:6.1.19] at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:466) [jetty-6.1.19.jar:6.1.19] at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) [jetty-util-6.1.19.jar:6.1.19] at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130) [jetty-6.1.19.jar:6.1.19] at org.mortbay.jetty.Server.doStart(Server.java:224) [jetty-6.1.19.jar:6.1.19] at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) [jetty-util-6.1.19.jar:6.1.19] at com.emacle.httpstorageserv.HttpStorageServ.main(HttpStorageServ.java:145) [bin/:na] Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.zcloudMVC.service.TestService com.zcloudMVC.controller.PlanController.testService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.zcloudMVC.mapper.TestMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER, lookup=)} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:558) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] ... 30 common frames omitted Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.zcloudMVC.mapper.TestMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER, lookup=)} at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:308) ~[spring-context-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1127) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1051) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:530) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] ... 32 common frames omitted 贴出一部分 注解扫描 mapper扫描我都配置了,xml扫描路径也配置, 在service层没问题,怎么注入mapper的时候就报错了,求解 ![图片说明](https://img-ask.csdn.net/uploa![图片说明](https://img-ask.csdn.net/upload/201803/23/1521795969_267447.png)d/201803/23/1521795939_362694.png) ![图片说明](https://img-ask.csdn.net/upload/201803/23/1521795981_368559.png)
推荐 130 个令你眼前一亮的网站,总有一个用得着
总结了大学生活两年来,发现的 130 余个黑科技网站,总有一个会让你眼前一亮,赶紧收藏!
在中国程序员是青春饭吗?
今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...
我在支付宝花了1分钟,查到了女朋友的开房记录!
在大数据时代下,不管你做什么都会留下蛛丝马迹,只要学会把各种软件运用到极致,捉奸简直轻而易举。今天就来给大家分享一下,什么叫大数据抓出轨。据史料证明,马爸爸年轻时曾被...
程序员请照顾好自己,周末病魔差点一套带走我。
程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。
卸载 x 雷某度!GitHub 标星 1.5w+,从此我只用这款全能高速下载工具!
作者 | Rocky0429 来源 | Python空间 大家好,我是 Rocky0429,一个喜欢在网上收集各种资源的蒟蒻… 网上资源眼花缭乱,下载的方式也同样千奇百怪,比如 BT 下载,磁力链接,网盘资源等等等等,下个资源可真不容易,不一样的方式要用不同的下载软件,因此某比较有名的 x 雷和某度网盘成了我经常使用的工具。 作为一个没有钱的穷鬼,某度网盘几十 kb 的下载速度让我...
20道你必须要背会的微服务面试题,面试一定会被问到
写在前面: 在学习springcloud之前大家一定要先了解下,常见的面试题有那块,然后我们带着问题去学习这个微服务技术,那么就会更加理解springcloud技术。如果你已经学了springcloud,那么在准备面试的时候,一定要看看看这些面试题。 文章目录1、什么是微服务?2、微服务之间是如何通讯的?3、springcloud 与dubbo有哪些区别?4、请谈谈对SpringBoot 和S...
讲真,这两个IDE插件,可以让你写出质量杠杠的代码
周末躺在床上看《拯救大兵瑞恩》 周末在闲逛的时候,发现了两个优秀的 IDE 插件,据说可以提高代码的质量,我就安装了一下,试了试以后发现,确实很不错,就推荐给大家。 01、Alibaba Java 代码规范插件 《阿里巴巴 Java 开发手册》,相信大家都不会感到陌生,其 IDEA 插件的下载次数据说达到了 80 万次,我今天又贡献了一次。嘿嘿。 该项目的插件地址: https://github....
为什么猝死的都是程序员,基本上不见产品经理猝死呢?
相信大家时不时听到程序员猝死的消息,但是基本上听不到产品经理猝死的消息,这是为什么呢? 我们先百度搜一下:程序员猝死,出现将近700多万条搜索结果: 搜索一下:产品经理猝死,只有400万条的搜索结果,从搜索结果数量上来看,程序员猝死的搜索结果就比产品经理猝死的搜索结果高了一倍,而且从下图可以看到,首页里面的五条搜索结果,其实只有两条才是符合条件。 所以程序员猝死的概率真的比产品经理大,并不是错...
毕业5年,我问遍了身边的大佬,总结了他们的学习方法
我问了身边10个大佬,总结了他们的学习方法,原来成功都是有迹可循的。
推荐10个堪称神器的学习网站
每天都会收到很多读者的私信,问我:“二哥,有什么推荐的学习网站吗?最近很浮躁,手头的一些网站都看烦了,想看看二哥这里有什么新鲜货。” 今天一早做了个恶梦,梦到被老板辞退了。虽然说在我们公司,只有我辞退老板的份,没有老板辞退我这一说,但是还是被吓得 4 点多都起来了。(主要是因为我掌握着公司所有的核心源码,哈哈哈) 既然 4 点多起来,就得好好利用起来。于是我就挑选了 10 个堪称神器的学习网站,推...
这些软件太强了,Windows必装!尤其程序员!
Windows可谓是大多数人的生产力工具,集娱乐办公于一体,虽然在程序员这个群体中都说苹果是信仰,但是大部分不都是从Windows过来的,而且现在依然有很多的程序员用Windows。 所以,今天我就把我私藏的Windows必装的软件分享给大家,如果有一个你没有用过甚至没有听过,那你就赚了????,这可都是提升你幸福感的高效率生产力工具哦! 走起!???? NO、1 ScreenToGif 屏幕,摄像头和白板...
阿里面试,面试官没想到一个ArrayList,我都能跟他扯半小时
我是真的没想到,面试官会这样问我ArrayList。
曾经优秀的人,怎么就突然不优秀了。
职场上有很多辛酸事,很多合伙人出局的故事,很多技术骨干被裁员的故事。说来模板都类似,曾经是名校毕业,曾经是优秀员工,曾经被领导表扬,曾经业绩突出,然而突然有一天,因为种种原因,被裁员了,...
大学四年因为知道了这32个网站,我成了别人眼中的大神!
依稀记得,毕业那天,我们导员发给我毕业证的时候对我说“你可是咱们系的风云人物啊”,哎呀,别提当时多开心啦????,嗯,我们导员是所有导员中最帅的一个,真的???? 不过,导员说的是实话,很多人都叫我大神的,为啥,因为我知道这32个网站啊,你说强不强????,这次是绝对的干货,看好啦,走起来! PS:每个网站都是学计算机混互联网必须知道的,真的牛杯,我就不过多介绍了,大家自行探索,觉得没用的,尽管留言吐槽吧???? 社...
良心推荐,我珍藏的一些Chrome插件
上次搬家的时候,发了一个朋友圈,附带的照片中不小心暴露了自己的 Chrome 浏览器插件之多,于是就有小伙伴评论说分享一下我觉得还不错的浏览器插件。 我下面就把我日常工作和学习中经常用到的一些 Chrome 浏览器插件分享给大家,随便一个都能提高你的“生活品质”和工作效率。 Markdown Here Markdown Here 可以让你更愉快的写邮件,由于支持 Markdown 直接转电子邮...
看完这篇HTTP,跟面试官扯皮就没问题了
我是一名程序员,我的主要编程语言是 Java,我更是一名 Web 开发人员,所以我必须要了解 HTTP,所以本篇文章就来带你从 HTTP 入门到进阶,看完让你有一种恍然大悟、醍醐灌顶的感觉。 最初在有网络之前,我们的电脑都是单机的,单机系统是孤立的,我还记得 05 年前那会儿家里有个电脑,想打电脑游戏还得两个人在一个电脑上玩儿,及其不方便。我就想为什么家里人不让上网,我的同学 xxx 家里有网,每...
2020 年,大火的 Python 和 JavaScript 是否会被取而代之?
Python 和 JavaScript 是目前最火的两大编程语言,但是2020 年,什么编程语言将会取而代之呢? 作者 |Richard Kenneth Eng 译者 |明明如月,责编 | 郭芮 出品 | CSDN(ID:CSDNnews) 以下为译文: Python 和 JavaScript 是目前最火的两大编程语言。然而,他们不可能永远屹立不倒。最终,必将像其他编程语言一...
史上最全的IDEA快捷键总结
现在Idea成了主流开发工具,这篇博客对其使用的快捷键做了总结,希望对大家的开发工作有所帮助。
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
这种新手都不会范的错,居然被一个工作好几年的小伙子写出来,差点被当场开除了。
谁是华为扫地僧?
是的,华为也有扫地僧!2020年2月11-12日,“养在深闺人不知”的华为2012实验室扫地僧们,将在华为开发者大会2020(Cloud)上,和大家见面。到时,你可以和扫地僧们,吃一个洋...
Flutter 会不会被苹果限制其发展?
这个可能性是存在的,而且不止是 flutter、react-native 、weex 、uni-app 、taro 、Hippy等都存在这个风险,虽然有些框架对比起 flutter 其他框架存在时间稍长,但是这不可否认它们一直都存在这个风向。 只要不是平台自己的亲儿子,那么肯定存在被限制发展的风险,所以这件事上是风险和收益之间的博弈,这是一个“后妈和前任之间的太极。” 先说现状 如今各大平台,如:...
没用过这些 IDEA 插件?怪不得写代码头疼
使用插件,可以提高开发效率。对于开发人员很有帮助。这篇博客介绍了IDEA中最常用的一些插件。
AI 没让人类失业,搞 AI 的人先失业了
最近和几个 AI 领域的大佬闲聊 根据他们讲的消息和段子 改编出下面这个故事 如有雷同 都是巧合 1. 老王创业失败,被限制高消费 “这里写我跑路的消息实在太夸张了。” 王葱葱哼笑一下,把消息分享给群里。 阿杰也看了消息,笑了笑。在座几位也都笑了。 王葱葱是个有名的人物,21岁那年以全额奖学金进入 KMU 攻读人工智能博士,累计发表论文 40 余篇,个人技术博客更是成为深度学习领域内风向标。 ...
2020年,冯唐49岁:我给20、30岁IT职场年轻人的建议
点击“技术领导力”关注∆每天早上8:30推送 作者|Mr.K 编辑| Emma 来源|技术领导力(ID:jishulingdaoli) 前天的推文《冯唐:职场人35岁以后,方法论比经验重要》,收到了不少读者的反馈,觉得挺受启发。其实,冯唐写了不少关于职场方面的文章,都挺不错的。可惜大家只记住了“春风十里不如你”、“如何避免成为油腻腻的中年人”等不那么正经的文章。 本文整理了冯...
最全最强!世界大学计算机专业排名总结!
我正在参与CSDN200进20,希望得到您的支持,扫码续投票5次。感谢您! (为表示感谢,您投票后私信我,我把我总结的人工智能手推笔记和思维导图发送给您,感谢!) 目录 泰晤士高等教育世界大学排名 QS 世界大学排名 US News 世界大学排名 世界大学学术排名(Academic Ranking of World Universities) 泰晤士高等教育世界大学排名 中国共...
作为一名大学生,如何在B站上快乐的学习?
B站是个宝,谁用谁知道???? 作为一名大学生,你必须掌握的一项能力就是自学能力,很多看起来很牛X的人,你可以了解下,人家私底下一定是花大量的时间自学的,你可能会说,我也想学习啊,可是嘞,该学习啥嘞,不怕告诉你,互联网时代,最不缺的就是学习资源,最宝贵的是啥? 你可能会说是时间,不,不是时间,而是你的注意力,懂了吧! 那么,你说学习资源多,我咋不知道,那今天我就告诉你一个你必须知道的学习的地方,人称...
那些年,我们信了课本里的那些鬼话
教材永远都是有错误的,从小学到大学,我们不断的学习了很多错误知识。 斑羚飞渡 在我们学习的很多小学课文里,有很多是错误文章,或者说是假课文。像《斑羚飞渡》: 随着镰刀头羊的那声吼叫,整个斑羚群迅速分成两拨,老年斑羚为一拨,年轻斑羚为一拨。 就在这时,我看见,从那拨老斑羚里走出一只公斑羚来。公斑羚朝那拨年轻斑羚示意性地咩了一声,一只半大的斑羚应声走了出来。一老一少走到伤心崖,后退了几步,突...
一个程序在计算机中是如何运行的?超级干货!!!
强烈声明:本文很干,请自备茶水!???? 开门见山,咱不说废话! 你有没有想过,你写的程序,是如何在计算机中运行的吗?比如我们搞Java的,肯定写过这段代码 public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } ...
【蘑菇街技术部年会】程序员与女神共舞,鼻血再次没止住。(文末内推)
蘑菇街技术部的年会,别开生面,一样全是美女。
Linux必懂知识大总结(补)
关机 1. 数据同步写入磁盘 sync 为了加快对磁盘上文件的读写速度,位于内存中的文件数据不会立即同步到磁盘上,因此关机之前需要先进行 sync 同步操作。 2. shutdown # /sbin/shutdown [-krhc] [时间] [警告讯息] -k : 不会关机,只是发送警告讯息,通知所有在线的用户 -r : 将系统的服务停掉后就重新启动 -h : 将系统的服务停掉后就...
立即提问