日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

spring学习(15):required属性

發布時間:2023/12/10 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 spring学习(15):required属性 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

CompactDisc類

package soundSystem;import org.springframework.stereotype.Component; //注解@Componentpublic 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 {@Autowired(required = false)private CompactDisc cd;@Autowiredprivate Power power;public CDPlayer() {super();System.out.println("CDPlayer無參構造方法");} /*@Autowiredpublic CDPlayer(CompactDisc cd) {this.cd = cd;System.out.println("CDPlayer有參構造方法");}*/ /*public CDPlayer(CompactDisc cd, Power power) {this.cd = cd;this.power = power;System.out.println("CDplayer的參數配置");}*/public void play(){power.supply();if(cd!=null) {cd.play();}} }

?

appconfig類

package soundSystem;import org.springframework.context.annotation.ComponentScan; //spring注解類 @ComponentScan public class Appconfig { }

power類

package soundSystem;import org.springframework.stereotype.Component;@Component public class Power {public Power() {super();}public void supply(){System.out.println("電源宮殿中..");} }

apptest類

package soundSystem;import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;//@RunWith(SpringJunit4ClassRunner.class) //@ContextConfiguration(class=) @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = Appconfig.class) public class AppTest {@Autowiredprivate CDPlayer player;@Testpublic void testPlay(){player.play();} }

運行結果

[INFO ] 2019-10-30 18:42:32,195 method:org.springframework.test.context.support.AbstractTestContextBootstrapper.getDefaultTestExecutionListenerClassNames(AbstractTestContextBootstrapper.java:260) Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener] [INFO ] 2019-10-30 18:42:32,203 method:org.springframework.test.context.support.AbstractTestContextBootstrapper.instantiateListeners(AbstractTestContextBootstrapper.java:209) Could not instantiate TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [javax/servlet/ServletContext] [INFO ] 2019-10-30 18:42:32,205 method:org.springframework.test.context.support.AbstractTestContextBootstrapper.instantiateListeners(AbstractTestContextBootstrapper.java:209) Could not instantiate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute] [INFO ] 2019-10-30 18:42:32,206 method:org.springframework.test.context.support.AbstractTestContextBootstrapper.instantiateListeners(AbstractTestContextBootstrapper.java:209) Could not instantiate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [org/springframework/transaction/interceptor/TransactionAttributeSource] [INFO ] 2019-10-30 18:42:32,208 method:org.springframework.test.context.support.AbstractTestContextBootstrapper.getTestExecutionListeners(AbstractTestContextBootstrapper.java:187) Using TestExecutionListeners: [org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@1786f9d5, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@704d6e83, org.springframework.test.context.support.DirtiesContextTestExecutionListener@43a0cee9][INFO ] 2019-10-30 18:42:32,393 method:org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:583) Refreshing org.springframework.context.support.GenericApplicationContext@4df828d7: startup date [Wed Oct 30 18:42:32 CST 2019]; root of context hierarchy [DEBUG] 2019-10-30 18:42:32,427 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-30 18:42:32,427 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449) Creating instance of bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor' [DEBUG] 2019-10-30 18:42:32,454 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-30 18:42:32,458 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485) Finished creating instance of bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor' [DEBUG] 2019-10-30 18:42:32,557 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-30 18:42:32,557 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449) Creating instance of bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor' [DEBUG] 2019-10-30 18:42:32,559 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-30 18:42:32,590 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485) Finished creating instance of bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor' [DEBUG] 2019-10-30 18:42:32,591 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-30 18:42:32,591 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449) Creating instance of bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor' [DEBUG] 2019-10-30 18:42:32,593 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-30 18:42:32,599 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485) Finished creating instance of bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor' [DEBUG] 2019-10-30 18:42:32,606 method:org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:730) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@158da8e: 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,appconfig,CDPlayer,power]; root of factory hierarchy [DEBUG] 2019-10-30 18:42:32,606 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-30 18:42:32,606 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-30 18:42:32,607 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-30 18:42:32,607 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-30 18:42:32,607 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449) Creating instance of bean 'org.springframework.context.event.internalEventListenerProcessor' [DEBUG] 2019-10-30 18:42:32,613 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-30 18:42:32,618 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485) Finished creating instance of bean 'org.springframework.context.event.internalEventListenerProcessor' [DEBUG] 2019-10-30 18:42:32,619 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-30 18:42:32,619 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449) Creating instance of bean 'org.springframework.context.event.internalEventListenerFactory' [DEBUG] 2019-10-30 18:42:32,620 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-30 18:42:32,623 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485) Finished creating instance of bean 'org.springframework.context.event.internalEventListenerFactory' [DEBUG] 2019-10-30 18:42:32,624 method:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221) Creating shared instance of singleton bean 'appconfig' [DEBUG] 2019-10-30 18:42:32,625 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449) Creating instance of bean 'appconfig' [DEBUG] 2019-10-30 18:42:32,626 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) Eagerly caching bean 'appconfig' to allow for resolving potential circular references [DEBUG] 2019-10-30 18:42:32,628 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485) Finished creating instance of bean 'appconfig' [DEBUG] 2019-10-30 18:42:32,629 method:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221) Creating shared instance of singleton bean 'CDPlayer' [DEBUG] 2019-10-30 18:42:32,629 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449) Creating instance of bean 'CDPlayer' CDPlayer無參構造方法 [DEBUG] 2019-10-30 18:42:32,634 method:org.springframework.beans.factory.annotation.InjectionMetadata.checkConfigMembers(InjectionMetadata.java:72) Registered injected element on class [soundSystem.CDPlayer]: AutowiredFieldElement for private soundSystem.CompactDisc soundSystem.CDPlayer.cd [DEBUG] 2019-10-30 18:42:32,634 method:org.springframework.beans.factory.annotation.InjectionMetadata.checkConfigMembers(InjectionMetadata.java:72) Registered injected element on class [soundSystem.CDPlayer]: AutowiredFieldElement for private soundSystem.Power soundSystem.CDPlayer.power [DEBUG] 2019-10-30 18:42:32,634 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-30 18:42:32,638 method:org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:86) Processing injected element of bean 'CDPlayer': AutowiredFieldElement for private soundSystem.CompactDisc soundSystem.CDPlayer.cd [DEBUG] 2019-10-30 18:42:32,648 method:org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:86) Processing injected element of bean 'CDPlayer': AutowiredFieldElement for private soundSystem.Power soundSystem.CDPlayer.power [DEBUG] 2019-10-30 18:42:32,653 method:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221) Creating shared instance of singleton bean 'power' [DEBUG] 2019-10-30 18:42:32,654 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:449) Creating instance of bean 'power' [DEBUG] 2019-10-30 18:42:32,655 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) Eagerly caching bean 'power' to allow for resolving potential circular references [DEBUG] 2019-10-30 18:42:32,658 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485) Finished creating instance of bean 'power' [DEBUG] 2019-10-30 18:42:32,658 method:org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.registerDependentBeans(AutowiredAnnotationBeanPostProcessor.java:535) Autowiring by type from bean name 'CDPlayer' to bean named 'power' [DEBUG] 2019-10-30 18:42:32,660 method:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:485) Finished creating instance of bean 'CDPlayer' [DEBUG] 2019-10-30 18:42:32,661 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251) Returning cached instance of singleton bean 'power' [DEBUG] 2019-10-30 18:42:32,662 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-30 18:42:32,762 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251) Returning cached instance of singleton bean 'lifecycleProcessor' [DEBUG] 2019-10-30 18:42:32,772 method:org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:86) Processing injected element of bean 'soundSystem.AppTest': AutowiredFieldElement for private soundSystem.CDPlayer soundSystem.AppTest.player [DEBUG] 2019-10-30 18:42:32,773 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251) Returning cached instance of singleton bean 'CDPlayer' [DEBUG] 2019-10-30 18:42:32,774 method:org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.registerDependentBeans(AutowiredAnnotationBeanPostProcessor.java:535) Autowiring by type from bean name 'soundSystem.AppTest' to bean named 'CDPlayer' 電源宮殿中.. [INFO ] 2019-10-30 18:42:32,783 method:org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:984) Closing org.springframework.context.support.GenericApplicationContext@4df828d7: startup date [Wed Oct 30 18:42:32 CST 2019]; root of context hierarchy [DEBUG] 2019-10-30 18:42:32,785 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:251) Returning cached instance of singleton bean 'lifecycleProcessor' [DEBUG] 2019-10-30 18:42:32,786 method:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:512) Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@158da8e: 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,appconfig,CDPlayer,power]; root of factory hierarchy

?

總結

以上是生活随笔為你收集整理的spring学习(15):required属性的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。