Insert picture description here

Mad Gentleman Says Spring Learning (2)_Shuang Jian 23’s Blog

class=”markdown_views prism-atom-one-dark”> Spring Learning (2) Eight, use java to configure spring The xml configuration of spring is not used at all, and it is all handed over to java JavaConfig is a sub-project of spring, and it has become a core function after spring4! //This will also be hosted by the Spring container and registered in the container, because it is originally a @Component //Configuration means that this is a configuration class, just like the beans.xml we saw before @Configuration @ComponentScan(“com.LH.pojo” ) @Import(Myconfig2.class) public class Myconfig { //Register a bean. It is equivalent to a bean tag 1 we wrote before //The name of this method is equivalent to the id country in the bean tag //The return value of this method is equivalent to the cLass attribute in the bean tag @Bean public User getUser(){ return new User ();// is to return The object injected into the bean } } //Indicates that this class has been taken over by spring @Component public class User { private String name; public String getName() { return name; } @Value(“pig”) public void setName(String name) { this.name = name; } @Override public String toString() { return “User{” + “name='” + name + ‘\” +…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索