Spring:HelloWorld:修订间差异

来自WHY42
imported>Soleverlee
以“=maven依赖= <source lang="xml"> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring}</version...”为内容创建页面
 
imported>Soleverlee
 
(未显示同一用户的1个中间版本)
第11行: 第11行:
<beans xmlns="http://www.springframework.org/schema/beans"
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">
xsi:schemaLocation="http://www.springframework.org/schema/beans  
                            http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">
<bean id="helloService" class="com.riguz.activity.HelloServiceImpl" />
<bean id="helloService" class="com.riguz.activity.HelloServiceImpl" />
<bean id="app" class="com.riguz.activity.App">
<bean id="app" class="com.riguz.activity.App">
第17行: 第18行:
</bean>
</bean>
</beans>   
</beans>   
</xml>
</source>
代码:
代码:
<source lang="java">
<source lang="java">
第40行: 第41行:


</source>
</source>
=基于注解的配置=
=基于注解的配置=
[[Category:Programe]]
[[Category:Programe]]

2016年11月18日 (五) 03:23的最新版本

maven依赖

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring}</version>
</dependency>

基于xml的配置

<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 
                            http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">
	<bean id="helloService" class="com.riguz.activity.HelloServiceImpl" />
	<bean id="app" class="com.riguz.activity.App">
		<property name="service" ref="helloService"></property>
	</bean>
</beans>

代码:

public class App {
    private HelloService service;

    public void setService(HelloService service) {
        this.service = service;
    }

    public void sayHello() {
        String msg = this.service.sayHello("Riguz");
        System.out.println(msg);
    }

    public static void main(String[] args) {
        ApplicationContext context =  new ClassPathXmlApplicationContext("spring-beans.xml");  
        App app = context.getBean(App.class);
        app.sayHello();
    }
}

基于注解的配置