I have a Spring Boot app which imports an external library. I am reading the spring.xml in the dependency that I have imported. It is throwing an error because it is looking for "propDir" which I have not defined. I see an error "Invalid bean definition with name .... Could not resolve placeholder 'propDir'"
<value>file:${propDir}/env-config.properties</value>
I have seen another spring boot app import the same dependency and it starts just fine. When I debugged the start sequence and saw the value of propDir , I saw that it was not substituted and I see "file:${propDir}/env-config.properties" in the created bean.
I have searched the app , but haven't really figured out how the other app is not throwing the error. Is there a piece of config that I am missing?
You need to specify a value for propDir.
This can be done either by jvm argument like
-DpropDir=nameoffoldertouse
or via a properties file loaded via a PropertyPlaceholderConfigurer.
Other applications that rely on this bean may have a default hidden away.
It is likely that the bean relying on this value will need it to guarantee its correct behaviour, if you do not want to provide this property do not rely on the bean that uses it.
Properties to a spring boot application can be passed using different ways, very likely for the other application the property for "propDir" is I believe getting passed as one of the ways specified in this documentation: http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
Related
I'm using OSGI with equinox, and having a problem on a new component dependency. It has two services references, which are both marked as 'Unsatisfied'.
This would be a simple unsatisfied references problem, it it weren't for the fact there is another component which uses one of this references and it's satisfied, the the other is a component which is satisfied on the system as well.
I've tried to debug the 'AgentServiceImpl' class to identify if this could be a problem on it's activation, but since it's references are unsatisfied the methods of the class aren't even called.
No clue of what I'm doing wrong on this case, any suggestion of fixes or ways to tackle this problem would be much appreciated.
[update]
I've noticed the Service I depend has this configuration on it's component declaration:
policy = ConfigurationPolicy.REQUIRE, configurationPid = "com.rm.ums.ruleengine"
So, if i don't define this, it should not build the component. However, even retrieving the ConfigurationAdmin and setting this configuration the component still won't go up. And there is no error message on the console for this, shouldn't it display an error or a warning in this case, so the developer know this is happening and can handle it?
It turns out this was a service configuration problem.
This component I was trying to inject had it's policy as 'REQUIRE', which means it won't start unless you provide it's configuration. I was providing the configuration on another bundle using the ConfigurationAdmin, but this configuration was being bonded to my bundle instead of the one which needs it.
Once I configured not to bind the configuration to my bundle (or unbind it manually), the service started as expected.
Probably this could be avoided case there was a warn message on the log stating this happened :(
I would like to make all property placeholder and their resolved values of a running Spring (Boot) application available for process monitoring. In the first step this could be just by writing them to the logs or by creating a 'resolved.properties' file similar to the application.pid file.
All properties where property placeholder are used (implicit/explicit) should be considered.
Motivation: It is usually hard during operation to know the values of resolved properties. System properties or command line arguments are "visible" but e.g. hidden default values in the code (like #Value("${timeout:30000}")) are hard to find out. I would like to be able to answer the question "How does the configuration of the running application looks like?" in a generic way that I can use in all of my spring applications.
I know about the Spring Boot Actuator /configprops endpoint, but this only includes #ConfigurationProperties. I would like to get a list of all properties where placeholder are used.
The requirement does not seem to be new (see here or here) but I wonder if there is an appropriate (bootiful) way nowadays.
There is (currently) no way to obtain all the properties in the Environment abstraction. This is intentional as can be read here. This is also why it isn't possible to obtain all the values used for resolution.
The values and resolutions are logged at runtime telling which key was resolved from where at runtime. But that logging is quite verbose and logged each time a StringValueResolver is used.
You might get a partial result by providing your own customized PropertySourcesPlaceholderConfigurer which maintains a collection of resolved key/value pairs. But not every resolution uses the PropertySourcesPlaceholderConfigurer some directly use a StringValueResolver implementation bypassing the PropertySourcesPlaceholderConfigurer.
It doesn't cover all your needs (ie: properties from all files, default values, application arguments, etc.).
I'll still keep the answer for other readers/future reference.
Spring Boot's Actuator /env endpoint
You may use the /env endpoint. It lists a bunch of stuff but it also includes the content of application.properties (near the end):
applicationConfig: [classpath:/application.properties]={myproperty=blah, server.port=8080}
Our application exports its configuration as several sets of Spring beans.
I have no control over how it does this.
I want to write something that documents the dependencies between the configuration items defined in these beans. Note: these are dependencies at the application level, nothing to so with Spring dependencies (so we might have configuration items of type Actresses who have a dependency on certain items from the type Bishops, but - at the Spring bean level - this is merely that the value of a property in the Actress matches the value of a different property of the Bishop).
So I'd like to use some library or toolset that lets me load up a set of bean definition XML, iterate over them and the content of each, extract property values and so on.
From some googling, I can find ways of extending the parsing Spring does itself, but I don't want that - I want something I can run offline outside of the Spring-using app itself.
Can someone point me at some resources for doing this?
The closest thing I've heard of to this is Spring BeanDocs:
http://spring-beandoc.sourceforge.net/
I am developing a SWT component in which there is a child component through which user can view the Spring reference and can change the Spring bean definition, property etc..
I am facing 2 issues:
If the defintion of bean is defined in some other Spring XML rather than the selected Spring file, then how to proceed.
How to fetch source code of class (for preview) from defined beanClass e.g. com.xyz.abc.def.Foo.
For getting the info from the spring xmls, you have to do some parsing, there is no beating around that. However you could use O/X Mappers to simplify this process http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/oxm.html
As codejammer said, you will have to parse all xml files and possibly also included files through different mechanisms. The safest would be to use Spring's own classes to deal with it. More specifically, see XmlBeanDefinitionReader[1] for reading and using a, possible custom, implementation of BeanDefinitionRegistry[2] for holding a map of your valid beans.
The second problem of loading the source for a class, that is as easy as changing the class' packet name to a fully qualified path: com.xyz.abc.def.Foo -> com/xyz/abc/def/Foo.java
http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/beans/factory/xml/XmlBeanDefinitionReader.html
http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/beans/factory/support/BeanDefinitionRegistry.html
I am configuring my spring application per-environemnt and I came to following problem:
As long as the environment changes just bean constructor/properties values I am fine with using PropertyPlaceholderConfigurer.
Now I am facing the fact that the bean structure itself change in different environemnts. E.g. in test environemnt I define single bean where in production environment I define another bean of same interface which requires property of type List set - in another words different structure where PropertyPlaceholderConfigurer can't really help.
I went with defining per-environment spring xml configuration importing it via <import resource="myDefinition-${Environment}.xml />. This is also fine until I want have it optional. The resource I am defining there is #Autowired(required = false) to another bean.
Since <import ... /> doesn't allow optional attribute (as can be seen here: https://jira.springsource.org/browse/SPR-1624) I ended up having empty .xml configuration files for environemnts where I don't require having that bean. This is somewhat inconvenient.
Could anyone advice on best practice in such scenario?
Thanks.
Bean definition profiles, introduced in Spring 3.1 are designed to solve just this kind of problem. See http://static.springsource.org/spring/docs/3.1.0.RC2/spring-framework-reference/html/new-in-3.1.html