当前位置:网站首页>@Component use cases
@Component use cases
2022-06-30 14:14:00 【Full stack programmer webmaster】
@component The role of the java Class to spring Manage in container , No <bean id=”” class=””> This configuration , In its place <context component-scan base-package=” Package name ” />, Responsible for scanning all package names under the changed package .
Case study :
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-4.0.xsd
">
<context:component-scan base-package="com.aa"></context:component-scan>
</beans>
package com.aa;
import org.springframework.stereotype.Component;
import com.introduce.Model.User2;
@Component("impl")
public class UserDaoImpl {
public User2 getUser2() {
return null;
}
public User2 getUser2(String name) {
User2 user2=new User2();
user2.setAge(22);
System.out.println(name+"s1");
return user2;
}
public void aa(){
System.out.println("bbbbb");
}
}
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.aa.UserDaoImpl;
public class Test4 {
@Autowired
private UserDaoImpl userDaoImpl;
@Test
public void test() {
// start-up spring Containers , Because it's a test class , So use applicationContext. If it is tomcat No need to start .
ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext5.xml");
userDaoImpl=(UserDaoImpl) ac.getBean("impl");
userDaoImpl.aa();
}
}
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/106264.html Link to the original text :https://javaforall.cn
边栏推荐
- Pit used by go language array type
- Go language func function
- Dart extended feature
- Lucky hash quiz system development (source code deployment) fun investment hash game play development (case requirements)
- Apache Doris comparison optimization Encyclopedia
- [Title brushing] heater
- 想請教一下,我在佛山,到哪裏開戶比較好?手機開戶是安全麼?
- The first three passes of sqli Labs
- Prometheus 2.29.0 new features
- Details of gets, fgetc, fgets, Getc, getchar, putc, fputc, putchar, puts, fputs functions
猜你喜欢
Heavyweight: the domestic ide was released, developed by Alibaba, and is completely open source!
步骤详解 | 助您轻松提交 Google Play 数据安全表单
MFQE 2.0: A New Approach for Multi-FrameQuality Enhancement on Compressed Video
Pytoch viewing model parameter quantity and calculation quantity
SQL programming problem, test case failed
[observation] as the intelligent industry accelerates, why should AI computing power take the lead?
深入理解.Net中的线程同步之构造模式(二)内核模式2.内核模式构造物Semaphone
Fastcgi CGI shallow understanding
Pytorch查看模型参数量和计算量
The programming competition is coming! B station surrounding, senior members and other good gifts to you!
随机推荐
Google Earth Engine(GEE)——GHSL:全球人类住区层,建成网格 1975-1990-2000-2015 (P2016) 数据集
"Persistent diseases" that cannot be solved in IM application development
Click the TD cell of table to open the dialog pop-up window. After obtaining the value, put the value back into the TD cell
Race of golang
MFQE 2.0: A New Approach for Multi-FrameQuality Enhancement on Compressed Video
More than 20 years after Hong Kong's return, Tupu digital twin Hong Kong Zhuhai Macao Bridge has shocked
想请教一下,我在佛山,到哪里开户比较好?手机开户是安全么?
【Redis 系列】redis 学习十六,redis 字典(map) 及其核心编码结构
I want to ask how to open an account at China Merchants Securities? Is it safe to open a stock account through the link
编程实战赛来啦!B站周边、高级会员等好礼送你啦!
Apache Doris comparison optimization Encyclopedia
数据恢复软件EasyRecovery15下载
目录相关命令
【科研数据处理】[基础]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)
DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703
Embedded development: five C features that may no longer be prohibited
Publicity of the fourth batch of shortlisted Enterprises - annual Top100 smart Internet supplier selection
单元测试效率优化:为什么要对程序进行测试?测试有什么好处?
Golang template (text/template)
[Title brushing] heater