GithubHelp home page GithubHelp logo

xlate / property-inject Goto Github PK

View Code? Open in Web Editor NEW
10.0 3.0 8.0 304 KB

Simple CDI extension to support injection of java.util.Properties values

License: GNU Affero General Public License v3.0

Java 100.00%
cdi-extension javaee

property-inject's Introduction

Property Inject build Coverage Quality Gate Status

Simple CDI extension to support injection of java.util.Properties values.

Please see the project wiki for more information.

Licensing

Property Inject is available for use under the GNU Affero GPL license for open source projects. Commercial license terms are also available (see COMM-LICENSE) for individuals or companies wishing to develop software using the library but do not wish to open source their own code. Please see the Property Inject product page for pricing.

property-inject's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar mikeedgar avatar mueller-jens avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

property-inject's Issues

Jakarta version

I was updating my projects to Jakarta and this is one of the projects that does not have a Jakarta version. I spent some time and created a fork and few sub projects to have jakarta support.

Pull Request incoming, so we can discuss about changes.

resolveEnvironment Issue

Hi,

I am using the following code within a POJO:

@Inject @Property(resolveEnvironment = true) private String abc;

I have created an environment variable of the same name, but always get an exception while Injecting the property and assigning the value.

Queries:

  1. Is the syntax correct as mentioned above?
  2. The code is deployed to JBOSS as WAR and have included the dependent JAR . Is it correct?

Kindly help.

Thanks
Milind

Exception if properties file missing

I have an example working in my web application, but as I am sending this to customers , they may not have my properties file yet ( or forget to install it ) so I don't want the application server to crash. Here's the simple class :

`
@ManagedBean(name = "adminProperties", eager=true)
@ApplicationScoped
public class adminProperties implements Serializable{

public static String SECURITY_NONE = "None";
public static String SECURITY_LOW = "Low";
public static String SECURITY_MED = "Medium";
public static String SECURITY_HIGH = "High";

@Inject
@Property( resource = @PropertyResource("classpath:lattice-admin.properties"), defaultValue = "Medium" )
private String securityLevel;

public String getSecurityLevel() {
    return securityLevel;
}

public void setSecurityLevel(String securityLevel) {
    this.securityLevel = securityLevel;
}

}`

When I run it in my web app without the properties file it crashes the app
`
Caused by: java.lang.RuntimeException: javax.enterprise.inject.InjectionException: javax.enterprise.inject.InjectionException: Class-path resource not found: lattice-admin.properties
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:292)
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:5394)
at com.sun.enterprise.web.WebModule.contextListenerStart(WebModule.java:743)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5963)
... 26 more
Caused by: javax.enterprise.inject.InjectionException: javax.enterprise.inject.InjectionException: Class-path resource not found: lattice-admin.properties
at io.xlate.inject.PropertyProducerBean.produceProperty(PropertyProducerBean.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:88)
at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:78)
at org.jboss.weld.injection.producer.ProducerMethodProducer.produce(ProducerMethodProducer.java:95)
at org.jboss.weld.injection.producer.AbstractMemberProducer.produce(AbstractMemberProducer.java:167)
at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:183)
at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:69)
at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:101)
at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:761)
at org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:861)
at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:92)
at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:375)
at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:386)
at org.jboss.weld.injection.producer.ResourceInjector$1.proceed(ResourceInjector.java:70)
at org.glassfish.weld.services.InjectionServicesImpl.aroundInject(InjectionServicesImpl.java:172)
at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:46)
at org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:72)
at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:121)
at org.glassfish.weld.services.JCDIServiceImpl.injectManagedObject(JCDIServiceImpl.java:285)
at org.glassfish.faces.integration.GlassFishInjectionProvider.inject(GlassFishInjectionProvider.java:189)
at com.sun.faces.mgbean.BeanBuilder.injectResources(BeanBuilder.java:203)
at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:101)
at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:256)
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:259)
... 29 more
Caused by: javax.enterprise.inject.InjectionException: Class-path resource not found: lattice-admin.properties
at io.xlate.inject.ClasspathURLStreamHandler.openConnection(ClasspathURLStreamHandler.java:24)
at java.net.URL.openConnection(URL.java:979)
at java.net.URL.openStream(URL.java:1045)
at io.xlate.inject.PropertyFactory.getProperties(PropertyFactory.java:150)
at io.xlate.inject.PropertyFactory.getProperty(PropertyFactory.java:134)
at io.xlate.inject.PropertyProducerBean.getProperty(PropertyProducerBean.java:263)
at io.xlate.inject.PropertyProducerBean.produceProperty(PropertyProducerBean.java:52)
... 59 more

`

I assumed that I would get the default value ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.