以下是我修改后的spring-context.xml
<bean id="sampleApacheConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" lazy-init="true">
<property name="brokerURL" value="tcp://localhost:61616"/>
<property name="userName" value=“kodeseeker"/>
<property name="password" value=“mypassword"/>
</bean>
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<constructor-arg ref="sampleApacheConnectionFactory" />
</bean>
<!-- Default Destination Queue Definition-->
<bean id="defaultDestination" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg index="0" value="test.Foo"/>
</bean>
<!-- JmsTemplate Definition -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<property name="defaultDestination" ref="defaultDestination" />
</bean>
<!-- Message Sender Definition -->
<bean id="messageSender" class="com.mypackage.Publisher2">
</bean>
<!-- Message Receiver Definition -->
<bean id="messageReceiver" class="com.mypackage.Listener">
</bean>
<bean class="org.springframework.jms.listener.SimpleMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory" />
<property name="destinationName" value="test.Foo" />
<property name="messageListener" ref="messageReceiver" />
</bean>
<context:component-scan base-package="com.mypackage" />
<bean name=“publisher" class=“com.mypackage.Publisher2"/>
<bean name="updateHandler" class="com.mypackage.UpdateHandlerImpl”/>
</beans>
首先收到请求的传入类。
package com.mypackage
@ComponentScan
@Controller
@Path("/")
public class BaseApiImpl {
…..
@Context
HttpHeaders headers;
@Autowired
UpdateHandlerImpl updateHandler;
@PUT
@Path("v1/“)
@Consumes("application/json")
@Produces({ "application/json" })
public PutTransactionsResponse updateTransactions(
UpdateTransactionsRequest entity)
throws Exception {
// @formatter:on
LOGGER.entry();
try {
//updateHandler is always Null!
return updateHandler.handle(new UpdateTransactionsMessage(headers.getRequestHeaders(), entity));
} catch (Exception e) {
LOGGER.catching(e);
} finally {
LOGGER.exit();
}
}
但是,尽管使用@Controller
注释了类并在上下文文件中声明了bean。我发现updateHandler
始终为空。我到底错在了什么?
答案 0 :(得分:0)
创建一个Jersey Config类并将其注册为bean并删除@Component
类上的@ComponentScan
和BaseApiImpl
,希望它应该可以工作,在我的情况下我使用Spring启动。
import org.glassfish.jersey.server.ResourceConfig;
import javax.ws.rs.ApplicationPath;
@ApplicationPath(value = "/<contextpath>")
public class JerseyConfig extends ResourceConfig{
public JerseyConfig() {
packages(true, "<your @Path classes package>");
}
}