Set System Properties in JSF+Spring Application - spring

I am developing a web application using JSF 2.0 ,Spring 3.1.
When I am deploying my application I am getting following error
ERROR [ContextLoader] Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'AllProjectDetailsBean' defined in ServletContext resource [/WEB-INF/springApp-spring.xml]: Could not resolve placeholder 'OutputFilePath'
Application Context file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ">
<aop:aspectj-autoproxy />
<bean id="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
</bean>
<bean id="AllProjectDetailsBean"
class="com.tcs.srl.expertFinder.sections.ProjectDetailsBeanFactory"
factory-method="createInstance">
<constructor-arg index="0" value="${OutputFilePath}" />
</bean>
What I understand from error is when I deploy application the context loads very first time but it fails because it dose not find any property with name OutputFilePath.
That means I have to set system property with the name OutputFilePath before context loads.
Can some tell me how to set system property while deploying jsf application or before context loads.
Or is there any option to remove this error.
Please Help
Thanks

Related

In Spring/Tomcat, which configuration file do jndi lookups refer to?:

I'm having trouble getting a Spring/Tomcat app to resolve a variable which appears as a property of a JndiFactoryObjectName bean in the application context. Here's the relevant bean entry:
When I try to run it on the server, it comes up with this error:
Caused by: javax.naming.NameNotFoundException: Name search.url is not bound in this Context
This entry in server.xml doesn't seem to help:
There's also an entry in (as seen from Eclipse/STS)
Tomcat v6.0 Server at localhost
Catalina
localhost
ROOT.xml
<Context path="" reloadable="true" docBase="C:/myworkspace32/myAppName/WebContent">
<ResourceLink global="search.url" name="search.url" type="java.lang.String"/>
</Context>
However, this seem to have no impact.
Here are the steps to access JNDI resource from tomcat
Create jndi resource in server.xml
<Resource global="search.url" name="search.url" type="java.lang.String" />
Create the link in context.xml so that its accessible by all the web application.
<ResourceLink name="search.url" global="search.url" auth="Container" type="java.lang.String" />
Use spring bean or jee tag to inject the jndi
<bean id="searchUrl" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/search.url"/>
</bean>
you can avoid specify the environment by using jee contatiner tag as follows
<jee:jndi-lookup id="searchUrl" jndi-name="search.url" expected-type="java.lang.String" />
Follow an example of Tomcat JNDI with Spring
Spring configuration
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<jee:jndi-lookup id="yourDS" jndi-name="java:comp/env/yourDS"/>
Tomcat configuration (put this in ${catalina.home}\conf\context.xml)
<Resource
name="yourDS"
type="javax.sql.DataSource"
username="****"
password="*****"
driverClassName="com.ibm.db2.jcc.DB2Driver"
url="*******"
maxActive="8"
maxIdle="4"
/>

unable to reference Spring services in JUnit

i am running a Karaf container with a number of beans implementing the com.mycompany.foo.IMyBean interface. i refer to them as "child beans". each such "child" bean is registered as a service. i also have a single "parent" bean that rounds up all those "child" services by using osgi:list. everything works just fine in runtime. however, when i run a very simple JUnit scenario, i get the following exception:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'BeanRefsList': Invocation of init method
failed; nested exception is java.lang.IllegalArgumentException:
Required 'bundleContext' property was not set.
this is the context.xml in my JUnit project:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd
">
<bean id="ChildBean"
class="com.mycompany.foo.ChildBean">
</bean>
<osgi:service id="ChildBeanService" ref="ChildBean" interface="com.mycompany.foo.IMyBean"/>
<osgi:list id="BeanRefsList" interface="com.mycompany.foo.IMyBean"/>
<bean id="ParentBean" class="com.mycompany.foo.ParentBean">
<property name="childBeans" ref="BeanRefsList"/>
</bean>
</beans>
the test class also contains the following annotation entries:
#org.junit.runner.RunWith(SpringJUnit4ClassRunner.class)
#org.springframework.test.context.ContextConfiguration("context.xml")
please let me know what i am doing wrong. thank you for your time!
The error message explains it pretty clearly. The line that says
<osgi:list id="BeanRefsList" interface="com.mycompany.foo.IMyBean"/>
Needs too look more like
<bean id="ParentBean" class="com.mycompany.foo.ParentBean">
<property name="childBeans" ref="BeanRefsList"/>
</bean>
Where the property "bundleContext" gets set properly. I'm not familiar with OSGI, so I don't know what class/object needs to be set here. But, that's what's missing.
I'm not sure what OSGI is looking for that's making it tell you "bundleContext" property is missing, but it sounds like both osgi:list and osgi:service use some kind of bundleContext property.
Have you specified all of the same imported schemas in jUnit that you did for your runtime context?

Loading util:properties with Spring Profile causes multiple occurrences of ID

I am using Spring(3.1) profiles to load property files vis util:properties:
<beans profile="local">
<util:properties id="myProps"
location="classpath:local.properties" />
</beans>
<beans profile="dev">
<util:properties id="myProps"
location="classpath:dev.properties" />
</beans>
And I invoke the profile via a runtime parameter(running on TC Server):-Dspring.profiles.active=local
But I get the error There are multiple occurrences of ID value 'myProps'
This was running previously with other bean definitions but once the util:properties was added I get the error.
Make sure your xsd declarations are using >= 3.1 versions for both beans and util namespaces:
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd ">
Most likely cause of error would be forgetting to set util declaration to 3.1, if as you say this works for other beans but not those declared using util.

Spring systemProperties not appending value properly

I am using Spring 3.1 to create a bean in an web application like below wherein the server contains -DCONFIG_MODE=dev. However, it seems spring is only resolving the filename to configuration.dev without appending the remaining .xml. Could you please point what could be wrong in this.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ws="http://jax-ws.dev.java.net/spring/core"
xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://jax-ws.dev.java.net/spring/core http://jax-ws.dev.java.net/spring/core.xsd
http://jax-ws.dev.java.net/spring/servlet http://jax-ws.dev.java.net/spring/servlet.xsd">
<bean id="xmlConfig" class="org.quwic.itms.mq.XmlConfiguration" init-method="init">
<constructor-arg type="java.net.URL" value="classpath:configuration.#{systemProperties.CONFIG_MODE}.xml"/>
<constructor-arg type="org.apache.commons.configuration.reloading.ReloadingStrategy" ref="reloadingStrategy"/>
</bean>
<!-- The managed reloading strategy for the configuration bean -->
<bean id="reloadingStrategy" class="org.apache.commons.configuration.reloading.FileChangedReloadingStrategy">
<property name="refreshDelay" value="300000"/>
</bean>
</beans>
Thanks,
Fixed it. I wrongly specified the system property as "-DCONFIG_MODE=local -Dprogram.name=JBossTools: JBoss 5.0 Runtime" rather than -DCONFIG_MODE=local "-Dprogram.name=JBossTools: JBoss 5.0 Runtime"

spring social xml config

i have already read the spring social document but the part of configuration is Java based, but my project's configuration is xml based. so please tell me how config spring social in spring xml config file. thank you and sorry for my poor english
Posting your code and issues will help us to provide you the best solution. Refer to the link below may be that is what you are looking for
http://harmonicdevelopment.tumblr.com/post/13613051804/adding-spring-social-to-a-spring-mvc-and-spring
Take a look at the example xml config
https://github.com/SpringSource/spring-social-samples/tree/master/spring-social-showcase-xml/src/main/webapp/WEB-INF/spring
You have to create a social config xml file and you have to import to your root-context.xml file. Also, you may think about configure your app with spring security. It's depends of your project architecture.
Sample spring social xml config file :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:social="http://www.springframework.org/schema/social"
xmlns:facebook="http://www.springframework.org/schema/social/facebook" xmlns:bean="http://java.sun.com/jsf/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/social http://www.springframework.org/schema/social/spring-social.xsd
http://www.springframework.org/schema/social/facebook http://www.springframework.org/schema/social/spring-social-facebook.xsd">
<!-- Ensures that configuration properties are read from a property file -->
<context:property-placeholder location="file:${sampleapp.appdir}/conf/appparam.txt"/>
<!--
Configures FB and Twitter support.
-->
<facebook:config app-id="${facebook.clientId}" app-secret="${facebook.clientSecret}" />
<!--
Configures the connection repository. This application uses JDBC
connection repository which saves connection details to database.
This repository uses the data source bean for obtaining database
connection.
-->
<social:jdbc-connection-repository data-source-ref="sampleappDS" connection-signup-ref="accountConnectionSignup"/>
<!--
This bean is custom account connection signup bean for your registeration logic.
-->
<bean id="accountConnectionSignup" class="com.sampleapp.social.AccountConnectionSignup"></bean>
<!--
This bean manages the connection flow between the account provider and
the example application.
-->
<bean id="connectController" class="org.springframework.social.connect.web.ConnectController" autowire="constructor">
<constructor-arg index="0" ref="connectionFactoryLocator"/>
<constructor-arg index="1" ref="connectionRepository"/>
</bean>
Sample root-context.xml :
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<!-- Scan for Spring beans declared via annotations. -->
<context:component-scan base-package="com.sampleapp"/>
<context:annotation-config/>
<context:property-placeholder location="file:${sampleapp.appdir}/conf/appparam.txt"/>
<cache:annotation-driven/>
<!-- Root Context: defines shared resources visible to all other web components -->
<import resource="security-config.xml"/>
<import resource="classpath*:spring/bean-context.xml"/>
<import resource="classpath*:spring/persistence-config.xml"/>
<import resource="social-config.xml"/>
<aop:aspectj-autoproxy proxy-target-class="true"/>

Resources