Spring file configuration with conditions - java

In my spring configuration I am loading a file with all the cxf services when I start a test. Sometimes, I don't want load these services on my tests because aren't necessary and I want work quickly.
I have all my cxf services loaded in this way:
<import resource="classpath:services-app-ib-es-test.xml" />
Can I change this line to read it only on conditional way? Something like this:
<if javavm param loadcxf = true>
<import resource="classpath:services-app-ib-es-test.xml" />
</if>
Edit: I am using spring-core-2.55
Thanks

With Spring 3.1 you could use the Profile feature, giving the profile as JM argument or in a property file.
I don't know about spring 2.x.
http://docs.spring.io/spring/docs/3.2.0.RELEASE/spring-framework-reference/html/new-in-3.1.html
http://spring.io/blog/2011/02/14/spring-3-1-m1-introducing-profile/
http://spring.io/blog/2011/02/11/spring-framework-3-1-m1-released/

Related

How to handle xml file path given using regular expression to support multiple environment for Integration Testing by Spring?

I have following configuration in my test-appContext.xml file for supporting execution of spring integration testing.
<bean id="cacheManagerConfig" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="file:/web/${websphere.env}/${websphere.Domain}/${websphere.Name}/myportal/config/ehcache.xml"/>
</bean>
I am using junit 4.12 with spring 4 for Integration Testing of MVC flow.
How to handle ehcache.xml file path in spring integration testing.
Thanks :)
I got the solution, as expression retrieving value from System Property which jvm.options file in case of Liberty server so i used following code in test case class.
static {
System.setProperty("websphere.env", "test");
System.setProperty("websphere.Domain", "mytestdomain");
System.setProperty("websphere.Name", "mytestdomain");
}
Its working fine.

BridgePropertyPlaceholderConfigurer camel bean

I use the following bean to manage properties in camel as below :
<bean id="ilePropertiesConfigurer"
class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
<property name="properties" ref="allProperties" />
</bean>
allproperties is a java class. it works very well when starting the application.
But now, I want to update properties without restarting my application. I update allproperties but it still takes the old values.
Can you help me?
This is not supported in Apache Camel with that Spring property placeholder bridge. You need to restart your application.
OSGi Blueprint has a concept of allowing to reload/restart your application when properties are changed, but it does a full bundle restart command.

Spring MVC putting values into XML Config file

I am working a Spring MVC project and in my Service object I need some information like system password, id, url etc but I would like to put this into one of the XML files so it can be changes without changing code.. which XML should I put it in and how do I read it into the object
Moving constants to XML is a first step, but to make your application truly configurable you should use external .properties file:
<context:property-placeholder location="file:///foo/bar/conf.properties" />
And then use it everywhere in your XML configuration:
<property name="password" value="${db_password}"/>
Where conf.properties contains:
db_password=secret
Note that you can also place properties file inside WAR (with location="classpath:/foo/bar/conf.properties").
If you are a happy user of Spring 3.1 (currently RC2) you can take advantage of new #PropertySourceannotation:
#Configuration
#PropertySource("classpath:/com/myco/app.properties")

Using Apache Camel and Spring, can I build uri using properties?

I have created my own component and I want to do something similar to this:
<camel:camelContext id="camel1">
<camel:route>
<camel:from uri="mysch://realthing?network=${network}" id="testEndpoint"/>
I want ${network} to come from a properties file (using Spring properties placeholder):
<context:property-placeholder location="classpath:test.properties"/>
How can I do that?
See this FAQ
http://camel.apache.org/how-do-i-use-spring-property-placeholder-with-camel-xml.html

Does Spring 3.0 provides a service definition file?

I'm wondering about Spring 3.0 whether it provides an automatically generated service definition page after I defined services.
With SOAP we have a WSDL file which contains WHAT, HOW and WHERE we can call a service.
Is that possible with Spring 3.0 or not?
Yes it does. Just add "?WSDL" to the URL of your Spring-generated web service and you'll get the definition. Also you can append "?xsd=1" instead and you'll get the schema you need (this is referenced also from the WSDL).
You can use an MBeanExporter to expose all of your services via JMX, which would be viewable through a JMX dashboard on your container (IE Tomcat, Jboss, etc). This is an easy way to account for 'what is deployed'. Your question is not entirely clear what sort of artifact you're looking for though.
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="autodetect" value="true"/>
</bean>
Will automatically export all of your defined beans as MBeans. Usually that's not entirely what you want, so alternatively, you'll specify them manually.
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="bean:name=testBean1" value-ref="testBean"/>
</map>
</property>
</bean>
I agree with Chochos.
These[?wsdl, ?xsd=N] are universal standard to find the service definition file and any Datacontract defined in the wsdl.
example:
if http://localhost:8080/MyService is your service endpoint then it is service container's responsibility to make the WSDl available at http://localhost:8080/MyService,
by default.
The answer is Yes,
Use tag in your message dispatcher spring context file.
if your message dispatcher bean id is spring-ws then the spring context file for it would be spring-ws-servlet.xml.
In that context file,
import the namespace http://www.springframework.org/schema/web-services/web-services-2.0.xsd
xmlns:sws="http://www.springframework.org/schema/web-services".
then use the tag dynamic-wsdl from this namespace.
Also, you can set attributes for it like portType, binding and id. This will generate the wsdl file for you. You can view it by querying for it in the browser
/.wsdl

Categories

Resources