Я хочу предоставить push-уведомления в проекте Spring MVC, используя JDK 1.6 для всех браузеров. Я последовал за this post и, наконец, решил пойти с Atmosphere. Для событий сервера посланных мой контроллера сервера (source):Интеграция атмосферы с весной MVC
@Controller
public class AtmosphereController {
@RequestMapping(value="/getTime", method=RequestMethod.GET)
@ResponseBody
public void websockets(final AtmosphereResource atmosphereResource) {
final HttpServletRequest request = atmosphereResource.getRequest();
final HttpServletResponse response = atmosphereResource.getResponse();
atmosphereResource.suspend();
final Broadcaster bc = atmosphereResource.getBroadcaster();
bc.scheduleFixedBroadcast(new Callable<String>() {
public String call() throws Exception {
return (new Date()).toString();
}
}, 10, TimeUnit.SECONDS);
}
}
Во время работы я получил org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.atmosphere.cpr.AtmosphereResource]: Specified class is an interface
. В решении этого вопроса я получил this relevant post. Я добавил это к моему диспетчерскому-servlet.xml:
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
</list>
</property>
</bean>
<mvc:annotation-driven>
<mvc:argument-resolvers>
<bean id= "atmosphereResource"
class="org.atmosphere.cpr.AtmosphereResourceImpl" />
</mvc:argument-resolvers>
</mvc:annotation-driven>
Делая это, также приводит к новой ошибке:
[cvc-complex-type.2.1: Element 'mvc:annotation-driven' must have no character or element information item [children], because the type's content type is empty.]
Я также попытался this. Пожалуйста, помогите мне ввести AtmosphereResource в контроллер весны. Нужно ли мне также обновлять web.xml или какой-либо другой файл конфигурации, чтобы заставить его работать или какую часть мне не хватает. Пожалуйста помоги! Просьба также прокомментировать другие варианты обеспечения функциональности серверных событий. Заранее спасибо!
аргумент-распознаватель правильно? Does AtmosphereResourceImpl реализует весну MethodArgumentResolver ?? –