spring学习(10):创建项目(自动装配)

首先创建项目

pom.xml的配置文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.geyao</groupId><artifactId>spring01geyao</artifactId><version>1.0-SNAPSHOT</version><dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>4.3.13.RELEASE</version></dependency><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency></dependencies>
</project>

配置log4j的配置文件

### 设置###
log4j.rootLogger = INFO,stdout### 输出信息到控制抬 ###
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
log4j.category.org.springframework.beans.factory=DEBUG

CompactDisc类

package soundSystem;import org.springframework.stereotype.Component;@Component
public class CompactDisc {public CompactDisc() {super();System.out.println("compactdisc无参构造方法");}public void play(){System.out.println("正在播放音乐....");}
}

CDplay类

package soundSystem;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;@Component
public class CDPlayer {private CompactDisc cd;public CDPlayer() {super();System.out.println("CDPlayer无参构造方法");}
@Autowiredpublic CDPlayer(CompactDisc cd) {this.cd = cd;System.out.println("CDPlayer有参构造方法");}public void play(){cd.play();}
}

App类

package soundSystem;import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;@ComponentScan
public class App {public static void main(String[] args){ApplicationContext context=new AnnotationConfigApplicationContext(App.class);CDPlayer player=context.getBean(CDPlayer.class);player.play();}
}

运行结果

[INFO ] 2019-10-29 18:56:54,850 method:org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:583)
Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@880ec60: startup date [Tue Oct 29 18:56:54 CST 2019]; root of context hierarchy
[DEBUG] 2019-10-29 18:56:54,874 method:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
Creating shared instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
[DEBUG] 2019-10-29 18:56:54,875 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449)
Creating instance of bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
[DEBUG] 2019-10-29 18:56:54,900 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
Eagerly caching bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor' to allow for resolving potential circular references
[DEBUG] 2019-10-29 18:56:54,904 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485)
Finished creating instance of bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
[DEBUG] 2019-10-29 18:56:54,995 method:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
Creating shared instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
[DEBUG] 2019-10-29 18:56:54,996 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449)
Creating instance of bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
[DEBUG] 2019-10-29 18:56:54,997 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
Eagerly caching bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor' to allow for resolving potential circular references
[DEBUG] 2019-10-29 18:56:55,030 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485)
Finished creating instance of bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
[DEBUG] 2019-10-29 18:56:55,030 method:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
Creating shared instance of singleton bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
[DEBUG] 2019-10-29 18:56:55,031 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449)
Creating instance of bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
[DEBUG] 2019-10-29 18:56:55,032 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
Eagerly caching bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor' to allow for resolving potential circular references
[DEBUG] 2019-10-29 18:56:55,040 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485)
Finished creating instance of bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
[DEBUG] 2019-10-29 18:56:55,046 method:org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:730)
Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@166fa74d: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,app,CDPlayer,compactDisc]; root of factory hierarchy
[DEBUG] 2019-10-29 18:56:55,047 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251)
Returning cached instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
[DEBUG] 2019-10-29 18:56:55,047 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251)
Returning cached instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
[DEBUG] 2019-10-29 18:56:55,050 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251)
Returning cached instance of singleton bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
[DEBUG] 2019-10-29 18:56:55,050 method:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
Creating shared instance of singleton bean 'org.springframework.context.event.internalEventListenerProcessor'
[DEBUG] 2019-10-29 18:56:55,051 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449)
Creating instance of bean 'org.springframework.context.event.internalEventListenerProcessor'
[DEBUG] 2019-10-29 18:56:55,059 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
Eagerly caching bean 'org.springframework.context.event.internalEventListenerProcessor' to allow for resolving potential circular references
[DEBUG] 2019-10-29 18:56:55,063 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485)
Finished creating instance of bean 'org.springframework.context.event.internalEventListenerProcessor'
[DEBUG] 2019-10-29 18:56:55,064 method:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
Creating shared instance of singleton bean 'org.springframework.context.event.internalEventListenerFactory'
[DEBUG] 2019-10-29 18:56:55,064 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449)
Creating instance of bean 'org.springframework.context.event.internalEventListenerFactory'
[DEBUG] 2019-10-29 18:56:55,065 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
Eagerly caching bean 'org.springframework.context.event.internalEventListenerFactory' to allow for resolving potential circular references
[DEBUG] 2019-10-29 18:56:55,070 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485)
Finished creating instance of bean 'org.springframework.context.event.internalEventListenerFactory'
[DEBUG] 2019-10-29 18:56:55,072 method:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
Creating shared instance of singleton bean 'app'
[DEBUG] 2019-10-29 18:56:55,072 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449)
Creating instance of bean 'app'
[DEBUG] 2019-10-29 18:56:55,073 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
Eagerly caching bean 'app' to allow for resolving potential circular references
[DEBUG] 2019-10-29 18:56:55,076 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485)
Finished creating instance of bean 'app'
[DEBUG] 2019-10-29 18:56:55,076 method:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
Creating shared instance of singleton bean 'CDPlayer'
[DEBUG] 2019-10-29 18:56:55,077 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449)
Creating instance of bean 'CDPlayer'
[DEBUG] 2019-10-29 18:56:55,120 method:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
Creating shared instance of singleton bean 'compactDisc'
[DEBUG] 2019-10-29 18:56:55,121 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449)
Creating instance of bean 'compactDisc'
compactdisc无参构造方法
[DEBUG] 2019-10-29 18:56:55,123 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
Eagerly caching bean 'compactDisc' to allow for resolving potential circular references
[DEBUG] 2019-10-29 18:56:55,126 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485)
Finished creating instance of bean 'compactDisc'
[DEBUG] 2019-10-29 18:56:55,127 method:org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:757)
Autowiring by type from bean name 'CDPlayer' via constructor to bean named 'compactDisc'
CDPlayer有参构造方法
[DEBUG] 2019-10-29 18:56:55,129 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
Eagerly caching bean 'CDPlayer' to allow for resolving potential circular references
[DEBUG] 2019-10-29 18:56:55,131 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485)
Finished creating instance of bean 'CDPlayer'
[DEBUG] 2019-10-29 18:56:55,131 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251)
Returning cached instance of singleton bean 'compactDisc'
[DEBUG] 2019-10-29 18:56:55,132 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251)
Returning cached instance of singleton bean 'org.springframework.context.event.internalEventListenerFactory'
[DEBUG] 2019-10-29 18:56:55,194 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251)
Returning cached instance of singleton bean 'lifecycleProcessor'
[DEBUG] 2019-10-29 18:56:55,199 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251)
Returning cached instance of singleton bean 'CDPlayer'
正在播放音乐....

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/424534.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[密码学基础][每个信息安全博士生应该知道的52件事][Bristol Cryptography][第21篇]CRT算法如何提高RSA的性能?

CRT加速RSA&#xff1a;https://www.di-mgt.com.au/crt_rsa.html 转载链接&#xff1a;https://www.cnblogs.com/zhuowangy2k/p/12245513.html

动态规划——最长递增子序列

题目 我们有一个数字序列包含 n 个不同的数字&#xff0c;如何求出这个序列中的最长递增子序列长度&#xff1f;比如 2, 9, 3, 6, 5, 1, 7 这样一组数字序列&#xff0c;它的最长递增子序列就是 2, 3, 5, 7&#xff0c;所以最长递增子序列的长度是 4。 回溯法 数组长度为n&a…

spring学习(11):使用配置类

CompactDisc类 package soundSystem;import org.springframework.stereotype.Component;Component public class CompactDisc {public CompactDisc() {super();System.out.println("compactdisc无参构造方法");}public void play(){System.out.println("正在播…

[密码学基础][每个信息安全博士生应该知道的52件事][Bristol Cryptography][第22篇]如何用蒙哥马利算法表示一个数字和多个相乘的数字

这是一系列博客文章中最新的一篇&#xff0c;该文章列举了“每个博士生在做密码学时应该知道的52件事”:一系列问题的汇编是为了让博士生们在第一年结束时知道些什么。 安全和效率 密码学的目标是设计高度安全的密码学协议,但是同时这些协议也应该被有效率的实现.这样就可以一…

动态规划——双11既可以薅羊毛还能花钱最少

淘宝的“双十一”购物节有各种促销活动&#xff0c;比如“满 200 元减 50 元”。假设你的购物车中有 n 个&#xff08;n>100&#xff09;想买的商品&#xff0c;希望从里面选几个&#xff0c;在凑够满减条件的前提下&#xff0c;让选出来的商品价格总和最大程度地接近满减条…

spring学习(12):使用junit4进行单元测试

pom.xml <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation"http://maven.apache.org/POM/4.0.0 …

[密码学基础][每个信息安全博士生应该知道的52件事][Bristol Cryptography][第23篇]写一个实现蒙哥马利算法的C程序

这是一系列博客文章中最新的一篇&#xff0c;该文章列举了“每个博士生在做密码学时应该知道的52件事”:一系列问题的汇编是为了让博士生们在第一年结束时知道些什么。 这次博客我将通过对蒙哥马利算法的一个实际的实现&#xff0c;来补充我们上周蒙哥马利算法的理论方面。这个…

spring学习(13):使用junit4进行单元测试续

加入spring test.jar包 pom.xml <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation"http://maven…

《java程序员修炼之道》pdf书籍

链接&#xff1a;https://pan.baidu.com/s/1bbsTPCpUNI9klh40-8Be7w 提取码&#xff1a;pc57 转载于:https://www.cnblogs.com/pyweb/p/10995145.html

[密码学基础][每个信息安全博士生应该知道的52件事][Bristol Cryptography][第24篇]描述一个二进制m组的滑动窗口指数算法

这是一系列博客文章中最新的一篇&#xff0c;该文章列举了“每个博士生在做密码学时应该知道的52件事”:一系列问题的汇编是为了让博士生们在第一年结束时知道些什么。 二进制算法 二进制模幂算法和传统的求幂的二次方方法非常像。实际上&#xff0c;唯一的不同就是我们把N表示…

第五十八期:从0到1 手把手教你建一个区块链

近期的区块链重回热点&#xff0c;如果你想深入了解区块链&#xff0c;那就来看一下本文&#xff0c;手把手教你构建一个自己的区块链。 作者&#xff1a;Captain编译 近期的区块链重回热点&#xff0c;如果你想深入了解区块链&#xff0c;那就来看一下本文&#xff0c;手把手…

动态规划——硬币找零思路

找零的两种问题 硬币找零问题&#xff0c;有两种。一种用贪心解决&#xff0c;一种用动态规划解决。 问题1&#xff1a;假设我们有 v1&#xff0c;v2&#xff0c;……&#xff0c;vn&#xff08;单位是元&#xff09;这些币值的硬币&#xff0c;它们的张数分别是 c1、c2、…, …

[密码学基础][每个信息安全博士生应该知道的52件事][Bristol Cryptography][第25篇]使用特殊的素数定义GF(p)和GF(2^n)的方法

这是一系列博客文章中最新的一篇&#xff0c;该文章列举了“每个博士生在做密码学时应该知道的52件事”:一系列问题的汇编是为了让博士生们在第一年结束时知道些什么。 当实现密码学方案时&#xff0c;一个最频繁调用的操作就是模运算。不幸的是&#xff0c;尽管模块化的使用非…

第五十九期:如何在Windows 10中执行Windows Defender离线扫描?

如果你使用Windows并经常上网浏览&#xff0c;强烈建议使用防病毒/安全保护软件。Windows 10随带一款名为Windows Defender/Security的内置防病毒保护工具&#xff0c;在过去几年不断成熟&#xff0c;已成为一种优秀的安全解决方案。 作者&#xff1a;布加迪编译 如果你使用Wi…

[密码学基础][每个信息安全博士生应该知道的52件事][Bristol Cryptography][第26篇]描述NAF标量乘法算法

这是一系列博客文章中最新的一篇&#xff0c;该文章列举了“每个博士生在做密码学时应该知道的52件事”:一系列问题的汇编是为了让博士生们在第一年结束时知道些什么。 [1] Hankerson, Darrel, Scott Vanstone, and Alfred J. Menezes. “Guide to elliptic curve cryptography…

第六十一期: 从7600万个5G连接中,我们发现了7种最有前景的5G物联网应用

近日&#xff0c;物联网市场调研机构IoT Analytics调研了44种不同的5G物联网用例&#xff0c;预计到2025年&#xff0c;这些用例将覆盖7600万个5G节点&#xff0c;本文重点介绍了其中7种最有市场前景的5G物联网用例。 作者&#xff1a;物联网智库 5G是第五代移动通信技术&…

动态规划——变形的杨辉三角形

我们现在对杨辉三角进行一些改造。每个位置的数字可以随意填写&#xff0c;经过某个数字只能到达下面一层相邻的两个数字。 假设你站在第一层&#xff0c;往下移动&#xff0c;我们把移动到最底层所经过的所有数字之和&#xff0c;定义为路径的长度。请你编程求出从最高层移动…

第六十期:玩了分布式这么久,你不会连Kafka都不清楚吧

Kafka 现在在企业和互联网项目中的应用越来越多了&#xff0c;本篇文章就从 Kafka 的基础开始带你一展 Kafka 的宏图。 作者&#xff1a;cxuan Kafka 现在在企业和互联网项目中的应用越来越多了&#xff0c;本篇文章就从 Kafka 的基础开始带你一展 Kafka 的宏图。 图片来自 Pe…

[密码学基础][每个信息安全博士生应该知道的52件事][Bristol Cryptography][第29篇]什么是UF-CMA数字签名的定义?

这是一系列博客文章中最新的一篇&#xff0c;该文章列举了“每个博士生在做密码学时应该知道的52件事”:一系列问题的汇编是为了让博士生们在第一年结束时知道些什么。 第16篇博客给出了DSA&#xff0c;Schnoor和RSA-FDH签名方案的细节&#xff0c;但是签名方案是什么&#xff…

第六十二期:看完这篇还不了解Nginx,那我就哭了!

看完这篇还不了解Nginx&#xff0c;那我就哭了&#xff01; Nginx 同 Apache 一样都是一种 Web 服务器。基于 REST 架构风格&#xff0c;以统一资源描述符(Uniform Resources Identifier)URI 或者统一资源定位符(Uniform Resources Locator)URL 作为沟通依据&#xff0c;通过 …