当前位置:网站首页>@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
边栏推荐
- I'd like to ask you, where can I open an account in Foshan? Is it safe to open a mobile account?
- Implementation of forwarding server using IO multiplexing
- 编程实战赛来啦!B站周边、高级会员等好礼送你啦!
- Problems in QT creator (additional unknown and error lines are listed in the debug output window)
- 【科研数据处理】[实践]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)
- DNS resolution home network access public DNS practice
- Talk about Vue's two terminal diff algorithm, analysis of the rendering principle of the mobile terminal, and whether the database primary key must be self incremented? What scenarios do not suggest s
- [scientific research data processing] [practice] frequency analysis chart of category variables, distribution chart of numerical variables and normality test (including lognormal)
- Jetpack compose for perfect screen fit
- Google Earth Engine(GEE)——GHSL:全球人类住区层,建成网格 1975-1990-2000-2015 (P2016) 数据集
猜你喜欢

半导体动态杂谈

About the problems encountered when using the timer class to stop with a button (why does the QPushButton (for the first time) need to be clicked twice to respond?)

MySQL back to table query optimization

IM即时通讯应用开发中无法解决的“顽疾”

【 scientific literature measurement 】 mining and visualization of keywords in foreign and Chinese Literature

Go language mutex lock

香港回归20余年,图扑数字孪生港珠澳大桥,超震撼

Unity animator parameter

Detailed explanation of the first three passes of upload Labs
![[observation] as the intelligent industry accelerates, why should AI computing power take the lead?](/img/61/b446a616e86247507c27390505dc6b.jpg)
[observation] as the intelligent industry accelerates, why should AI computing power take the lead?
随机推荐
DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703
Calculates the length of the last word in a string, separated by spaces
Advanced usage of go language for loop break and continue
Chapter 13 signal (III) - example demonstration
目录相关命令
@component使用案例
Directory related commands
深入理解.Net中的线程同步之构造模式(二)内核模式3.内核模式构造物Mutex
Flat shading with unity
Google Earth engine (GEE) - ghsl: global human settlements layer, built grid 1975-1990-2000-2015 (p2016) data set
Problems in QT creator (additional unknown and error lines are listed in the debug output window)
Notes on reverse learning in the first week of winter vacation
Dart extended feature
What network security problems are exposed when a large-scale QQ number theft event occurs?
Pit used by go language array type
Deep understanding Net (2) kernel mode 2 Kernel mode construct semaphone
(8)JMeter元件详解之 Once only Controller 仅一次控制器
[Title brushing] coco, who likes bananas
DNS resolution home network access public DNS practice
科普达人丨漫画图解什么是eRDMA?