Estos son mis principios. Si a usted no le gustan, tengo otros

Spring Annotations Inject properties / Anotaciones Spring Inyectar properties

Posted: December 4th, 2009 | Author: Edu | Filed under: Java, Spring | Tags: , | No Comments »
VN:F [1.9.2_1090]
Rating: 0.0/5 (0 votes cast)

applicationContext.xml:

File parameters.properties / Fichero parameters.properties:

MyComponent.path=/some/path

Spring component / Componente gestionado por Spring:

import javax.annotation.PostConstruct;
import org.springframework.stereotype.Component;
 
@Component("MyComponent")
public class MyComponent {
 
    private String path;
 
    @PostConstruct
    public void loadPath() {
 
        System.out.println("Loading from " + this.path);
    }
 
    public String getPath() {
        return path;
    }
 
    public void setPath(String path) {
        this.path = path;
    }
}
VN:F [1.9.2_1090]
Rating: 0.0/5 (0 votes cast)

Simple Javascript call from Java / Llamada simple a Javascript desde Java

Posted: December 4th, 2009 | Author: Edu | Filed under: Java, Javascript, Scripting | Tags: , , | No Comments »
VN:F [1.9.2_1090]
Rating: 0.0/5 (0 votes cast)

Simple call / Llamada simple:

1
2
3
4
5
6
7
8
9
10
11
try {
	ScriptEngineManager factory = new ScriptEngineManager();
	ScriptEngine engine = factory.getEngineByName("JavaScript");
 
	//Simple call to println javascript function 
	engine.eval("println('Texto JavaScript')");
 
} catch (ScriptException ex) {
 
	//Do something
}

Calling a function / Llamando a una función:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
try {
 
	ScriptEngineManager factory = new ScriptEngineManager();
	ScriptEngine engine = factory.getEngineByName("JavaScript");
	engine.eval("function amessagefunction(atext){ return 'The secret message is ' + atext;}");
	Invocable invocable = (Invocable) engine;
	Object object = invocable.invokeFunction("amessagefunction", "abc");
	System.out.println(object);
 
} catch (NoSuchMethodException ex) {
 
	//Do something
 
} catch (ScriptException ex) {
 
	//Something is wrong, perhaps
}
VN:F [1.9.2_1090]
Rating: 0.0/5 (0 votes cast)