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 5fae804

Browse files
Spring archivo de propiedades externo
1 parent 7cbf224 commit 5fae804

File tree

10 files changed

+202
-0
lines changed

10 files changed

+202
-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_properties/nbactions.xml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<actions>
3+
<action>
4+
<actionName>run</actionName>
5+
<packagings>
6+
<packaging>jar</packaging>
7+
</packagings>
8+
<goals>
9+
<goal>process-classes</goal>
10+
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
11+
</goals>
12+
<properties>
13+
<exec.args>-classpath %classpath carmelo.spring.introduccion.Introduccion</exec.args>
14+
<exec.executable>java</exec.executable>
15+
</properties>
16+
</action>
17+
<action>
18+
<actionName>debug</actionName>
19+
<packagings>
20+
<packaging>jar</packaging>
21+
</packagings>
22+
<goals>
23+
<goal>process-classes</goal>
24+
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
25+
</goals>
26+
<properties>
27+
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath carmelo.spring.introduccion.Introduccion</exec.args>
28+
<exec.executable>java</exec.executable>
29+
<jpda.listen>true</jpda.listen>
30+
</properties>
31+
</action>
32+
<action>
33+
<actionName>profile</actionName>
34+
<packagings>
35+
<packaging>jar</packaging>
36+
</packagings>
37+
<goals>
38+
<goal>process-classes</goal>
39+
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
40+
</goals>
41+
<properties>
42+
<exec.args>-classpath %classpath carmelo.spring.introduccion.Introduccion</exec.args>
43+
<exec.executable>java</exec.executable>
44+
</properties>
45+
</action>
46+
</actions>

‎tutorial_properties/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_properties</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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package carmelo.spring.introduccion;
2+
3+
public class HelloServiceImpl implements HelloService {
4+
5+
private String msg;
6+
7+
public HelloServiceImpl(String msg) {
8+
this.msg = msg;
9+
}
10+
11+
@Override
12+
public void saludar() {
13+
System.out.println("\n--- " + msg + " ---\n");
14+
}
15+
}
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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package carmelo.spring.introduccion;
2+
3+
import java.io.BufferedReader;
4+
import java.io.FileReader;
5+
import java.io.IOException;
6+
import java.util.stream.Collectors;
7+
import org.springframework.beans.factory.annotation.Value;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
import org.springframework.context.annotation.PropertySource;
11+
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
12+
import org.springframework.core.io.Resource;
13+
14+
@Configuration
15+
@PropertySource("classpath:application.properties")
16+
public class SpringConfiguration {
17+
18+
@Value("${autor}")
19+
private String mensaje;
20+
21+
@Value("${classpath:web/index.html}")
22+
private Resource page;
23+
24+
@Bean
25+
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
26+
return new PropertySourcesPlaceholderConfigurer();
27+
}
28+
29+
@Bean
30+
public HelloService saludaService() throws IOException {
31+
32+
BufferedReader br = new BufferedReader(new FileReader(page.getFile()));
33+
String msg = br.lines().collect(Collectors.joining(System.lineSeparator()));
34+
35+
return new HelloServiceImpl(msg);
36+
}
37+
38+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mensaje: Hello Spring Framework
2+
autor= Tutor de programaci\u00f3n
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+
<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="discountPropertyConfigurer"
11+
class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
12+
<property name="location">
13+
<value>classpath:application.properties</value>
14+
</property>
15+
</bean> -->
16+
17+
<context:property-placeholder location="classpath:application.properties"/>
18+
19+
<bean id="saludaService" class="carmelo.spring.introduccion.HelloServiceImpl">
20+
<constructor-arg value="${mensaje}"/>
21+
</bean>
22+
23+
</beans>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>TODO supply a title</title>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
</head>
8+
<body>
9+
<div>TODO write content</div>
10+
</body>
11+
</html>

0 commit comments

Comments
(0)

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