Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a89b07e

Browse files
Introduccion a Spring Framework
En este tutorial vemos los distintos tipos de configuración que podemos usar para crear el contenedor IoC de Spring.
1 parent 648eddc commit a89b07e

File tree

7 files changed

+101
-0
lines changed

7 files changed

+101
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project-shared-configuration>
3+
<!--
4+
This file contains additional configuration written by modules in the NetBeans IDE.
5+
The configuration is intended to be shared among all the users of project and
6+
therefore it is assumed to be part of version control checkout.
7+
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
8+
-->
9+
<spring-data xmlns="http://www.netbeans.org/ns/spring-data/1">
10+
<config-files>
11+
<config-file>src/main/resources/springXMLConfig.xml</config-file>
12+
<config-file>src/main/resources/newSpringXMLConfig.xml</config-file>
13+
</config-files>
14+
<config-file-groups/>
15+
</spring-data>
16+
</project-shared-configuration>

‎tutorial_introduccion/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>carmelo.spring</groupId>
5+
<artifactId>tutorial_introduccion</artifactId>
6+
<version>1.0</version>
7+
<packaging>jar</packaging>
8+
9+
<dependencies>
10+
<dependency>
11+
<groupId>org.springframework</groupId>
12+
<artifactId>spring-context</artifactId>
13+
<version>4.3.6.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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package carmelo.spring.introduccion;
2+
3+
public interface HelloService {
4+
5+
void saludar();
6+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package carmelo.spring.introduccion;
2+
3+
public class HelloServiceImpl implements HelloService {
4+
5+
@Override
6+
public void saludar() {
7+
System.out.println("\n--- Hello Spring Framework ---\n");
8+
}
9+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package carmelo.spring.introduccion;
2+
3+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
4+
import org.springframework.context.support.AbstractApplicationContext;
5+
import org.springframework.context.support.ClassPathXmlApplicationContext;
6+
7+
public class Introduccion {
8+
9+
public static void main(String[] args) {
10+
11+
// configuracion con archivo XML
12+
//AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("springXMLConfig.xml");
13+
14+
// configuracion con codigo java
15+
AbstractApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfiguration.class);
16+
17+
HelloService saluda = ctx.getBean("saludaService", HelloService.class);
18+
saluda.saludar();
19+
20+
ctx.close();
21+
}
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package carmelo.spring.introduccion;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
6+
@Configuration
7+
public class SpringConfiguration {
8+
9+
@Bean
10+
public HelloService saludaService(){
11+
return new HelloServiceImpl();
12+
}
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:context="http://www.springframework.org/schema/context"
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
6+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
7+
8+
<!-- <context:component-scan base-package="carmelo.spring.introduccion"/> -->
9+
10+
<bean id="saludaService" class="carmelo.spring.introduccion.HelloServiceImpl"/>
11+
12+
</beans>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /