I am building OSGI bundle for running in Jboss Fuse 6.1 container. Project contains blueprint.xml (in src/main/resoureces/OSGI-INF/blueprint). It is content:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/blueprint"
xmlns:camelcxf="http://camel.apache.org/schema/blueprint/cxf"
xmlns:cxf="http://cxf.apache.org/blueprint/core"
xmlns:jaxws="http://cxf.apache.org/blueprint/jaxws"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
http://cxf.apache.org/blueprint/jaxws http://cxf.apache.org/schemas/blueprint/jaxws.xsd
http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd"
>
<bean id="MyProcessor" class="com.test.MyProcessor" />
<camelContext trace="false" id="blueprintContext" xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="activemq:queue:paymentsqueue?username=admin&password=admin" id="NotificationRoute">
<description/>
</from>
<log message="The message contains ${body}"/>
<process ref="MyProcessor"/>
</route>
</camelContext>
</blueprint>
My goal is using spring beans in MyProcessor. This is code for MyProcessor:
public class MyProcessor implements Processor {
#Aurowired
private Sender sender;
#Override
public void process(Exchange x) throws Exception {
log.info("test: " +sender.getSenderId());
}
}
But it gives me nullpointerexception. What I am doing wrong?
This is content of my spring configuration file(i placed it in src/main/resoureces/META-INF/spring)
<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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:annotation-config/>
<context:component-scan base-package="com.username"/>
<bean id="sender" class="com.username.Sender" scope="prototype">
<property name="senderId" value="sendername" />
<property name="password" value="senderpassword" />
</bean>
I think you have not declared the Processor MyProcessor as a bean in spring like
<bean id="myProcessor"
class="com.test.MyProcessor" />
then you can use it as
<process ref="myProcessor"/>
Also the
#Aurowired
private Sender sender;
should be #Autowired(This should be a typo but pointed it out.)
Related
<?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"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
>
<bean id="triangle1" class="groupid.aop.triangle">
<property name="name" value="triangle bean"></property>
</bean>
<bean id="circle1" class="groupid.aop.circle">
<property name="name" value="circle bean"></property>
</bean>
<aop:aspectj-autoproxy proxy-target-class="true"/>
<context:component-scan base-package="groupid.aop"/>
</beans>
im getting error on <context:component-scan base-package="groupid.aop"/>
this line. im using maven to add dependencies for both spring and aop dependencies. I also added namespace for context. please let me know if im missing anything.
You were wrong in namespaces declaration.
This xml should solve the issue:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
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.xsd">
<bean id="triangle1" class="groupid.aop.triangle">
<property name="name" value="triangle bean" />
</bean>
<bean id="circle1" class="groupid.aop.circle">
<property name="name" value="circle bean" />
</bean>
<aop:aspectj-autoproxy proxy-target-class="true" />
<context:component-scan
base-package="groupid.aop" />
</beans>
In your original XML you have:
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"
As you can see you declared twice spring-beans (http://www.springframework.org/schema/beans/spring-beans.xsd and http://www.springframework.org/schema/beans/spring-beans-3.0.xsd) and you used the 3.0 context version (http://www.springframework.org/schema/context/spring-context-3.0.xsd)
I hope it's usefull
Angelo
I have an application that has been developed (reworked) on Eclipse. It works fine in the development environment. However when it is loaded into Tomcat it fails with a namespace exception:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [camel-config.xml]
Offending resource: class path resource [spring-config.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [camel-config.xml]; nested exception is
org.springframework.beans.FatalBeanException: Invalid NamespaceHandler class [org.apache.camel.spring.handler.CamelNamespaceHandler] for namespace [http://camel.apache.org/schema/spring]: problem with handler class file or dependent class; nested excep
tion is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
my spring-config and camel-config are below
<?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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.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
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd">
<context:component-scan base-package="foo.bar.agent" />
<task:annotation-driven />
<import resource="camel-config.xml" />
</beans>
camel-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:camel="http://camel.apache.org/schema/spring" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- enable Spring #Component scan -->
<context:component-scan base-package="com.altegix.agent.hl7" />
<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
<property name="ignoreMissingLocation" value="true" />
<property name="locations">
<list>
<value>classpath:default.properties</value>
<value>file:/opt/altegix/agent/application.properties</value>
</list>
</property>
</bean>
<bean id="myhl7codec" class="org.apache.camel.component.hl7.HL7MLLPCodec">
<property name="charset" value="iso-8859-1" />
<property name="validate" value="false" />
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring"
id="resultsCamelContext">
<contextScan />
<camel:endpoint id="hl7listener"
uri="mina2:tcp://{{results.endpoint.server}}:{{results.endpoint.port}}?sync=true&codec=#myhl7codec" />
</camelContext>
<context:annotation-config />
<bean class="com.altegix.agent.hl7.HL7ListenerConfiguration" />
I don't understand why I would be getting a InvalidNamespace Exception? There is also the noClassDefFoundError which I have not seen before - maybe am I missing some classes that are in Eclipse?
Having the strangest problem right now - have a Spring XML file where the address property of the jaxws:client is using a property placeholder for the address attribute but it is refusing to resolve the address attribute.
This is the log file error:
Caused by: java.net.MalformedURLException: no protocol: ${member.service.uri}
at java.net.URL.(URL.java:567) ~[na:1.6.0_33]
at java.net.URL.(URL.java:464) ~[na:1.6.0_33]
at java.net.URL.(URL.java:413) ~[na:1.6.0_33]
at org.apache.cxf.transport.http.HTTPConduit.setupURL(HTTPConduit.java:700) ~[cxf-
bundle-2.6.0.jar:2.6.0]
at org.apache.cxf.transport.http.HTTPConduit.prepare(HTTPConduit.java:474) ~[cxf-
bundle-2.6.0.jar:2.6.0]
at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:46) ~[cxf-api-2.6.0.jar:2.6.0]
... 43 common frames omitted
Here is the excerpt from my Spring XML 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:http="http://cxf.apache.org/transports/http/configuration"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws" \
xmlns:sec="http://cxf.apache.org/configuration/security"
xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://cxf.apache.org/configuration/security
http://cxf.apache.org/schemas/configuration/security.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
<http:conduit name="https://.*">
<http:tlsClientParameters>
<sec:trustManagers>
<sec:keyStore type="JKS" password="${jkspass}" file="${jkslocation}" />
</sec:trustManagers>
</http:tlsClientParameters>
<http:client AutoRedirect="true" Connection="Keep-Alive" />
</http:conduit>
<!-- Member Service -->
<!--<bean id="memberServiceProxy" class="com.loyalty.tp.ets.common.member.ws.Member"
factory-bean="memberServiceProxyFactory" factory-method="create"/> -->
<jaxws:client id="memberServiceProxy"
serviceClass="com.loyalty.tp.ets.common.member.ws.Member"
address="${member.service.uri}">
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>
</jaxws:client>
<bean id="memberServiceProxyFactory"
class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="com.loyalty.tp.ets.common.member.ws.Member"/>
<property name="address" value="${member.service.uri}"/>
</bean>
<!-- ETS Collector Service -->
<bean id="collectorServiceProxy" class="com.loyalty.tp.ets.collectorservice.Collector"
factory-bean="collectorServiceProxyFactory" factory-method="create"/>
<bean id="collectorServiceProxyFactory"
class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="com.loyalty.tp.ets.collectorservice.Collector"/>
<property name="address" value="${ets.collector.service.uri}"/>
</bean>
</beans>
It resolves the ${jksLocation} and ${jkspassword} just fine. What is going on here ?
It seems to be an incompatibility between certain versions of cxf and spring try finding a couple wich work together.
I have camel-cxf:2.12.0.redhat-610379 which bring cxf 2.7.0 and spring 3.2.8.RELEASE and everything is ok
Hi need help in learniing basic spring .
i have a simple Aspect
#Aspect
public class HelloAspect {
static final Logger log = Logger.getLogger(HelloAspect.class .getClass().getName());
#Before("execution(* *.*(..))")
public void logBefore(JoinPoint joinPoint) {
log.info("The method " + joinPoint.getSignature().getName()+ "() begins with "+Arrays.toString(joinPoint.getArgs()));
}}
dispatcher-servlet.xml
<?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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema /tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<aop:aspectj-autoproxy />
<context:component-scan base-package="com"></context:component-scan>
<mvc:annotation-driven></mvc:annotation-driven>
<context:annotation-config></context:annotation-config>
<context:load-time-weaver/>
<bean class="com.abhi.aop.HelloAspect"/>
<!--
Most controllers will use the ControllerClassNameHandlerMapping above, but
for the index controller we are using ParameterizableViewController, so we must
define an explicit mapping for it.
-->
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="index.htm">indexController</prop>
</props>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<!--
The index controller.
-->
<bean name="indexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="index" />
</beans>
application-context.xml is
I have a simple entity from derby table and controller mapping
goal is to print logbefore logger before every method.
but i get nothing on server after deployment log.
Could I use SpEL inside the id attribute of a bean ?
e.g :
<bean id="#{T(com.om.m).PublicStaticFinalStringProperty}"...
This way it's not working, what should I change or it's not possible ?
Weird but possible (sample uses spring 3.1). Different versions working:
<?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: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/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
">
<context:property-placeholder properties-ref="myProps"/>
<util:properties id="myProps" >
<prop key="x.y.z">possible</prop>
</util:properties>
<bean id="testBean" class="Bean">
<property name="value" value="weird"/>
</bean>
<bean id="${x.y.z}" class="Bean">
<property name="value" value="but"/>
</bean>
<bean id="#{testBean.value}" class="Bean">
<property name="value" value="${x.y.z}"/>
</bean>
</beans>
Bean.java
public class Bean implements InitializingBean {
String value;
public void setValue(String value) {
this.value = value;
}
public void afterPropertiesSet() throws Exception {
System.out.println(value);
}
}