Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dbacd2f

Browse files
committed
Introducción a IoC con Spring
1 parent c5dcd42 commit dbacd2f

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

ioc/pom.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.carmelo</groupId>
5+
<artifactId>ioc</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
9+
<dependencies>
10+
<dependency>
11+
<groupId>org.springframework</groupId>
12+
<artifactId>spring-context</artifactId>
13+
<version>4.2.4.RELEASE</version>
14+
</dependency>
15+
</dependencies>
16+
17+
<properties>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
<maven.compiler.source>1.8</maven.compiler.source>
20+
<maven.compiler.target>1.8</maven.compiler.target>
21+
</properties>
22+
23+
</project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.carmelo.ioc;
7+
8+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
9+
import org.springframework.context.annotation.Bean;
10+
11+
/**
12+
*
13+
* @author Carmelo Marin Abrego
14+
*/
15+
public class Hello {
16+
17+
@Bean
18+
public HelloService helloBean() {
19+
return new HelloServiceImpl();
20+
}
21+
22+
public static void main(String[] args) {
23+
AnnotationConfigApplicationContext applicationContext
24+
= new AnnotationConfigApplicationContext(Hello.class);
25+
26+
HelloService hs = applicationContext.getBean(HelloService.class);
27+
28+
System.out.println(hs.saludar());
29+
}
30+
31+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.carmelo.ioc;
7+
8+
/**
9+
*
10+
* @author Carmelo Marin Abrego
11+
*/
12+
public interface HelloService {
13+
public String saludar();
14+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.carmelo.ioc;
7+
8+
9+
/**
10+
*
11+
* @author Carmelo Marin Abrego
12+
*/
13+
public class HelloServiceImpl implements HelloService {
14+
15+
@Override
16+
public String saludar() {
17+
return "Hola Mundo.";
18+
}
19+
20+
}

0 commit comments

Comments
 (0)