paip.spring 获取bean getBean 没有beanid的情况下

paip.spring 获取bean  getBean 没有beanid的情况下


spring能自动扫描带有注解的bean文件..


作者Attilax  艾龙,  EMAIL:1466519819@qq.com 
来源:attilax的专栏
地址:http://blog.csdn.net/attilax


设置
    <context:annotation-config />
<context:component-scan base-package="com.mijie.homi.search.dao.**"/>
<context:component-scan base-package="com.mijie.homi.search.service.**"/> 
这个时候儿,没有beanid在app.xml以及java文件中...
默认那是class名称,第一的字母小写..MoodUserIndexService.java >>>>   moodUserIndexService


ApplicationContext act=new FileSystemXmlApplicationContext("classpath:applicationContext.xml"); 
MoodUserIndexService moodUserService=  (MoodUserIndexService) act.getBean("moodUserIndexService"); 


参考
在应用程序中怎么自动加载Spring,并注入sessionFactory - ITeye问答.htm
Spring@Autowired注解与自动装配 - - 博客频道 - CSDN.NET.htm
Spring注解@Componen、@Repository@Service、@Controller区别 - 豆丁网.htm



原文地址:https://www.cnblogs.com/attilax/p/15199370.html