Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
package test.weldtest;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
public class App {
public static void main(String[] args) {
WeldContainer weld = new Weld().initialize();
weld.instance().select(HelloWorldWriter.class).get().sayIt();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans>
</beans>
package test.weldtest;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
public @interface Configuration {
}
package test.weldtest;
import java.io.IOException;
import java.util.Properties;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
public class ConfigurationFactory {
public @Produces @Configuration String getConfiguration(InjectionPoint ip) throws IOException {
Properties props = new Properties();
props.load(ConfigurationFactory.class.getResourceAsStream("/messages.properties"));
return props.getProperty(ip.getMember().getDeclaringClass().getSimpleName() + "." + ip.getMember().getName());
}
}
package test.weldtest;
import javax.inject.Inject;
public class HelloWorldWriter {
@Inject @Configuration
private String message;
public void sayIt() {
System.out.println(message);
}
}
HelloWorldWriter.message=Hello World!
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>weld-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>weld-test</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se</artifactId>
<version>1.1.10.Final</version>
</dependency>
</dependencies>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.