Springѧϰ֮·1
2020-03-17 16:10:08À´Ô´£º²©¿ÍÔ° ÔĶÁ ()
Springѧϰ֮·1
Spring ¿ò¼Ü
¼ò½é
Spring¿ò¼ÜÊÇÓÉÓÚÈí¼þ¿ª·¢µÄ¸´ÔÓÐÔ¶ø´´½¨µÄ
Ä¿µÄ£º½â¾öÆóÒµÓ¦Óÿª·¢µÄ¸´ÔÓÐÔ
¹¦ÄÜ£ºÊ¹Óûù±¾µÄJavaBean´úÌæEJB£¬²¢ÌṩÁ˸ü¶àµÄÆóÒµÓ¦Óù¦ÄÜ
·¶Î§£ºÈκÎJavaÓ¦ÓÃ
Óŵ㣺
¿ªÔ´µÄÃâ·ÑµÄ¿ò¼Ü£¨ÈÝÆ÷£©
SpringÊÇÒ»¸öÇáÁ¿¼¶¡¢·ÇÈëÇÖʽµÄ¿ò¼Ü
¿ØÖÆ·´×ª(IOC)ºÍÃæÏòÇÐÃæ(AOP)µÄÈÝÆ÷¿ò¼Ü
Ö§³ÖÊÂÎñµÄ´¦Àí£¬¶Ô¿ò¼ÜÕûºÏµÄÖ§³Ö
¹ÙÍø£ºhttps://spring.io/
GitHub£ºhttps://github.com/spring-projects/spring-framework
Maven
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.2.4.RELEASE</version>
</dependency>
spring Æß´óÄ£¿é
IOC ÀíÂÛ
IoC È«³ÆΪ Inversion of Control
£¬¼´¡°¿ØÖÆ·´×ª¡±£¬Spring µÄºËÐÄÄÚÈÝÖ®Ò»£¬ÊÇÒ»ÖÖͨ¹ýÃèÊö£¨xml »ò ×¢½â£©²¢Í¨¹ýµÚÈý·½»ñÈ¡Ìض¨¶ÔÏóµÄ·½Ê½£¬Spring ÖÐʵÏÖ¿ØÖÆ·´×ªµÄÊÇ IoC ÈÝÆ÷£¬ÆäʵÏÖ·½Ê½ÊÇ DI£¨Dependency Injection
£©,¼´ÒÀÀµ×¢Èë¡£
- Ë¿ØÖÆË£ºÔÚ´«Í³µÄ¿ª·¢Ä£Ê½Ï£¬ÎÒÃǶ¼ÊDzÉÓÃÖ±½Ó new Ò»¸ö¶ÔÏóµÄ·½Ê½À´´´½¨¶ÔÏó£¬Ò²¾ÍÊÇ˵ÄãÒÀÀµµÄ¶ÔÏóÖ±½ÓÓÉÄã×Ô¼º¿ØÖÆ£¬µ«ÊÇÓÐÁË IOC ÈÝÆ÷ºó£¬ÔòÖ±½ÓÓÉ IoC ÈÝÆ÷À´¿ØÖÆ¡£ËùÒÔ¡°Ë¿ØÖÆË¡±£¬µ±È»ÊÇ IoC ÈÝÆ÷¿ØÖƶÔÏó¡£
- ¿ØÖÆʲô£º¿ØÖƶÔÏó¡£
- ΪºÎÊÇ·´×ª£ºÃ»ÓÐ IoC µÄʱºòÎÒÃǶ¼ÊÇÔÚ×Ô¼º¶ÔÏóÖÐÖ÷¶¯È¥´´½¨±»ÒÀÀµµÄ¶ÔÏó£¬ÕâÊÇÕýת¡£µ«ÊÇÓÐÁË IoC ºó£¬ËùÒÀÀµµÄ¶ÔÏóÖ±½ÓÓÉ IoC ÈÝÆ÷´´½¨ºó×¢Èëµ½±»×¢ÈëµÄ¶ÔÏóÖУ¬ÒÀÀµµÄ¶ÔÏóÓÉÔÀ´µÄÖ÷¶¯»ñÈ¡±ä³É±»¶¯½ÓÊÜ£¬ËùÒÔÊÇ·´×ª¡£
- ÄÄЩ·½Ã淴תÁË£ºËùÒÀÀµ¶ÔÏóµÄ»ñÈ¡±»·´×ªÁË¡£
IoC´´½¨¶ÔÏó
ͨ¹ýxml´´½¨¶ÔÏó
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="he" class="com.youzi.pojo.Hello">
<property name="Str" value="Hello Spring!"/>
</bean>
</beans>
public class Hello {
private String Str;
public Hello(String str) {
Str = str;
}
public Hello() {
}
public String getStr() {
return Str;
}
public void setStr(String str) {
Str = str;
}
}
...
@Test
public void test() {
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
Object he = context.getBean("he");
System.out.println(he);
}
ÒýÓÃÁËÆäËû¶ÔÏóµÄ¸³Öµ·½Ê½£º
<bean id="userservice" class="com.youzi.service.UserServiceImpl">
<property name="user" ref="user"/>
</bean>
ûÓвÎÊýÖ±½Ó³õʼ»¯
<bean id="user" class="com.youzi.dao.UserImpl"/>
ÒÔÉÏ·½Ê½µ÷ÓÃÁ˶ÔÓ¦ÀàÖеÄÎ޲ι¹ÔìºÍ setter£¬¼´ÐèÒª³õʼ»¯µÄ²ÎÊý»òÕ߶ÔÏó±ØÐëÓжÔÓ¦µÄ setter£¬Èç¹ûÒªµ÷ÓÃÓвι¹Ôì¿ÉÒÔʹÓà <constructor-arg>
ͨ¹ýÀàÐÍ¡¢Ï±ꡢ²ÎÊýÃû×Ö¡¢ÒýÓÃÕ⼸ÖÖ·½Ê½´«²Î
ʹÓù¹ÔìÆ÷
public Users(Hello hello, String num) {
this.hello = hello;
this.num = num;
}
<bean id="users" class="com.youzi.pojo.Users">
<!--<constructor-arg type="java.lang.String" value="1"/>-->
<!--<constructor-arg index="1" value="2"/>-->
<constructor-arg name="num" value="3"/>
<constructor-arg ref="he"/>
</bean>
spring»ù±¾ÅäÖÃ
±ðÃû£¬¸ø¶ÔÏó´´½¨ÁíÒ»¸öÃû×Ö£¬¿É´´½¨¶à¸ö£¨±ðÃûÒ²¿ÉÒÔͨ¹ý bean ÖÐµÄ name
´´½¨£©
<bean id="he" class="com.youzi.pojo.Hello" name="hello3,hello4">
<property name="Str" value="Hello Spring!"/>
</bean>
<alias name="he" alias="hello1"/>
<alias name="he" alias="hello2"/>
bean ¶ÔÏóĬÈÏ´´½¨µÄΪµ¥Àýģʽ£¬¿ÉÒÔͨ¹ý
scope="prototype"
Ð޸ģ¬ÕâÑù hello3,hello4 ¾ÍÊÇÁ½¸ö²»Í¬µÄ¶ÔÏóÁË
ÉÏÃæÖ»ÊÇ»ù±¾µÄÅäÖã¬Ã¿¸öÅäÖÃÀïÃ滹ÓкܶàµÄϸ½ÚÅäÖôýÒÔºóÔÙ½øÒ»²½µÄѧϰ
ÔÎÄÁ´½Ó:https://www.cnblogs.com/wangjr1994/p/12514704.html
ÈçÓÐÒÉÎÊÇëÓëÔ×÷ÕßÁªÏµ
±êÇ©£º
°æȨÉêÃ÷£º±¾Õ¾ÎÄÕ²¿·Ö×ÔÍøÂ磬ÈçÓÐÇÖȨ£¬ÇëÁªÏµ£ºwest999com@outlook.com
Ìرð×¢Ò⣺±¾Õ¾ËùÓÐתÔØÎÄÕÂÑÔÂÛ²»´ú±í±¾Õ¾¹Ûµã£¬±¾Õ¾ËùÌṩµÄÉãÓ°ÕÕƬ£¬²å»£¬Éè¼Æ×÷Æ·£¬ÈçÐèʹÓã¬ÇëÓëÔ×÷ÕßÁªÏµ£¬°æȨ¹éÔ×÷ÕßËùÓÐ
ÉÏһƪ£ºQuartzÈëÃÅ (¶þ) SimpleTrigger
ÏÂһƪ£º¡¾ÊÓƵ+ͼÎÄ¡¿Java»ù´¡¾µäÁ·Ï°Ì⣨һ£©Êä³ö2-100Ö®¼äµÄËØÊý£¬¼°
- SpringϵÁÐ.ApplicationContext½Ó¿Ú 2020-06-11
- springboot2ÅäÖÃJavaMelodyÓëspringMVCÅäÖÃJavaMelody 2020-06-11
- ѧϰJava 8 Stream Api (4) - Stream Öն˲Ù×÷Ö® collect 2020-06-11
- javaѧϰ֮µÚÒ»Ìì 2020-06-11
- ¸øÄãÒ»·Ý³¬Ïêϸ Spring Boot ֪ʶÇåµ¥ 2020-06-11
IDC×ÊѶ£º Ö÷»ú×ÊѶ ×¢²á×ÊѶ ÍйÜ×ÊѶ vps×ÊѶ ÍøÕ¾½¨Éè
ÍøÕ¾ÔËÓª£º ½¨Õ¾¾Ñé ²ß»®Ó¯Àû ËÑË÷ÓÅ»¯ ÍøÕ¾Íƹã Ãâ·Ñ×ÊÔ´
ÍøÕ¾ÁªÃË£º ÁªÃËÐÂÎÅ ÁªÃ˽éÉÜ ÁªÃ˵ãÆÀ Íø׬¼¼ÇÉ
ÐÐÒµ×ÊѶ£º ËÑË÷ÒýÇæ ÍøÂçÓÎÏ· µç×ÓÉÌÎñ ¹ã¸æ´«Ã½
ÍøÂç±à³Ì£º Asp.Net±à³Ì Asp±à³Ì Php±à³Ì Xml±à³Ì Access Mssql Mysql ÆäËü
·þÎñÆ÷¼¼Êõ£º Web·þÎñÆ÷ Ftp·þÎñÆ÷ Mail·þÎñÆ÷ Dns·þÎñÆ÷ °²È«·À»¤
Èí¼þ¼¼ÇÉ£º ÆäËüÈí¼þ Word Excel Powerpoint Ghost Vista QQ¿Õ¼ä QQ FlashGet ѸÀ×
ÍøÒ³ÖÆ×÷£º FrontPages Dreamweaver Javascript css photoshop fireworks Flash
³ÌÐòÉè¼Æ£º Java¼¼Êõ C/C++ VB delphi
- Photoshop»æÖÆÁ¢Ìå·ç¸ñµÄ΢Ц±íÇé
- PSÎÄ×ÖÌØЧ½Ì³Ì£ºÖÆ×÷¹«Â·ÉϸöÐÔµÄÍ¿Ñ»
- PhotoshopÉè¼Æ¾í±ßЧ¹ûµÄ±äÐνð¸ÕµçÓ°
- PSÉ«²ÊÐÞ¸´½Ì³Ì£ºÀûÓÃÉ«½×¹¤¾ß¿ìËÙ¸øºì
- PS°ë͸Ã÷ÎïÌå¿Ùͼ£ºÀûÓÃͨµÀÑ¡Çø¹¤¾ß¿Ù
- PSº£±¨Éè¼Æ¼¼Çɽ̳̣ºÑ§Ï°ÖÆ×÷¸öÐԵč
- PSͼƬÌØЧÖÆ×÷½Ì³Ì£ºÑ§Ï°¸øÌúËþͼƬÖÆ
- ѧϰÓÃphotoshop°Ñ»ë×ǵĺ£Ë®ÕÕƬºóÆÚ
- PS¹Å·çÕÕƬ½Ì³Ì£º¸ø¹Å·çÃÀÅ®´òÔì³öÅ®ÏÀ
- PS¸öÐÔÈËÎﺣ±¨ÖÆ×÷£ºÉè¼Æ´´ÒâʱÉеIJ£
- ʲôÈí¼þ¿ÉÒÔµÁȡ΢ÐźÅÃÜÂë,ÔõôµÁ±ð
- ´ÅÁ¦ËÑË÷ÍøÕ¾µ¼º½2020Äê¸üÐÂ
- springcloudѧϰ֮·: (Ò») ×î¼òµ¥µÄ´î
- ´´½¨Gradle¹¤³Ì³öÏÖCould not install
- ³¹µ×Ū¶®¡°PKIX path building failed
- TomcatÆô¶¯±¨´í:org.apache.catalina.L
- spring boot ´íÎó£ºCheck your ViewRes
- »ùÓÚHttpClientµÄаæÕý·½½ÌÎñϵͳģÄâ
- Ö»ÓгÌÐòÔ±²ÅÄÜ¿´¶®µÄ³µÅÆ£¬¶®µÃ×ÔÈ»¶®
- mybatis ×¢½â@Results¡¢@Result¡¢@Resu