ҳ > > > Java >

Springѧϰ֮·1

2020-03-17 16:10:08Դ԰ Ķ ()

ǿߣٴȺLinuxʹ

Springѧϰ֮·1

Spring

SpringĸԶ

  • ĿģҵӦÿĸ

  • ܣʹûJavaBeanEJBṩ˸ҵӦù

  • ΧκJavaӦ

ŵ㣺

ԴѵĿܣ

SpringһʽĿ

Ʒת(IOC)(AOP)

֧ĴԿϵ֧

https://spring.io/

GitHubhttps://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 ʵַʽ DIDependency Injection,ע롣

  1. ˭˭ڴͳĿģʽ£ǶDzֱ new һķʽҲ˵ĶֱԼƣ IOC ֱ IoC ơԡ˭˭Ȼ IoC ƶ
  2. ʲôƶ
  3. ΪǷתû IoC ʱǶԼȥĶת IoC Ķֱ IoC ע뵽עĶУĶԭȡɱܣǷת
  4. Щ淴תĻȡתˡ

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ҪʼIJ߶жӦ 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 ͬĶ

xml

ֻǻãÿ滹кܶϸôԺٽһѧϰ



ԭ:https://www.cnblogs.com/wangjr1994/p/12514704.html
ԭϵ

ǩAVsysimgPOSTHTTPSweb

Ȩվ²磬Ȩϵwest999com@outlook.com
رע⣺վת۲վ۵㣬վṩӰƬ廭ƷʹãԭϵȨԭ

һƪQuartz () SimpleTrigger

һƪƵ+ͼġJavaϰ⣨һ2-100֮