Java Spring框架MVC4、JPA、Atmosphere jersey、实时通知
我需要在我们的webapp上发送推送通知。目前,我们使用Spring工具套件在Maven中使用Spring框架MVC构建应用程序。所有功能都已完成,但我们需要添加此实时通知功能,就像在facebook中使用Atmosphere jersey一样 我在发布这条消息之前,在网上到处搜索了一下 主要问题:SpringFrameworkMVC4是Atmosphere中的独立实例(实例或其他术语),因此我无法将服务从Spring自动连接到Atmosphere服务。请给我一些关于如何使用这些库的概念或想法 前端没有问题。刚被这个春天和气氛搞砸了 尝试了此问题的答案,但无效: 方法1:@可配置,@自动连线,但服务仍然为空 搜索没有: 使用@Configurable,它需要启用LTW(加载时编织),但当whwre-javaagent在vFabric TC服务器中有bug或其他什么东西时,它就被卡住了。- web.xmlJava Spring框架MVC4、JPA、Atmosphere jersey、实时通知,java,spring,spring-mvc,jersey,atmosphere,Java,Spring,Spring Mvc,Jersey,Atmosphere,我需要在我们的webapp上发送推送通知。目前,我们使用Spring工具套件在Maven中使用Spring框架MVC构建应用程序。所有功能都已完成,但我们需要添加此实时通知功能,就像在facebook中使用Atmosphere jersey一样 我在发布这条消息之前,在网上到处搜索了一下 主要问题:SpringFrameworkMVC4是Atmosphere中的独立实例(实例或其他术语),因此我无法将服务从Spring自动连接到Atmosphere服务。请给我一些关于如何使用这些库的概念或想法
<!-- Atmosphere -->
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet>
<description>AtmosphereServlet</description>
<servlet-name>AtmosphereServlet</servlet-name>
<servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>
<init-param>
<param-name>org.atmosphere.cpr.broadcasterLifeCyclePolicy</param-name>
<param-value>EMPTY_DESTROY</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.cpr.broadcaster.shareableThreadPool</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.cpr.recoverFromDestroyedBroadcaster</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.websocket.messageContentType</param-name>
<param-value>application/json</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AtmosphereServlet</servlet-name>
<url-pattern>/notification/*</url-pattern>
</servlet-mapping>
方法2:现在,尝试让用户从spring控制器连接到NotificationChannelController。但即使客户端在从spring控制器访问时连接到managedservice路径,仍然为null。我知道这不是正确的方法,但必须做一些技巧,使这项工作
控制器:
@Controller
@RequestMapping("secured/*")
public class BaseController {
private static final Logger LOGGER = LoggerFactory
.getLogger(BaseController.class);
@RequestMapping(value = "test", method = RequestMethod.GET)
@ResponseBody
public void testMethod() throws Exception {
System.out.println("AAAAAAAAAAAAAAAAAA");
NotificationChannelController ncc = new NotificationChannelController();
ncc.show();
}
}
通知信道控制器
@ManagedService(path = "/notification/{channel: [a-zA-Z][a-zA-Z_0-9]*}")
@Singleton
@Configurable(preConstruction=true,dependencyCheck=true,autowire=Autowire.BY_TYPE)
public final class NotificationChannelController {
private final Logger logger = LoggerFactory.getLogger(NotificationChannelController.class);
private final ConcurrentHashMap<String, String> users = new ConcurrentHashMap<String, String>();
public void show(){
System.out.println("A");
for(String key : users.keySet()){
System.out.println(key + " " + users.get(key));
}
System.out.println("B");
for(String s : getRooms(factory.lookupAll())){
System.out.println(s);
}
System.out.println("C");
}
}
@ManagedService(path=“/notification/{channel:[a-zA-Z][a-zA-Z_0-9]*}”)
@独生子女
@可配置(预构造=真,依赖性检查=真,自动连线=自动连线。按类型)
公共最终类通知ChannelController{
私有最终记录器Logger=LoggerFactory.getLogger(NotificationChannelController.class);
私有最终ConcurrentHashMap用户=新ConcurrentHashMap();
公开展览({
系统输出打印项次(“A”);
for(字符串键:users.keySet()){
System.out.println(key+“”+users.get(key));
}
系统输出打印项次(“B”);
for(字符串s:getRooms(factory.lookupAll())){
系统输出打印项次;
}
系统输出打印项次(“C”);
}
}
感谢您花时间阅读本文,我希望有人能对此有所启发。谢谢 实现Java已经有一段时间了,但是您不需要某种bean声明作为配置来获得一个自动连接的文件吗 在cxf教程的示例中,我将一个Dao自动连接到一个实例,bean本身在中定义 也许你可以看看,祝你好运 你读过《s-Classes-Creation-and-Injection》吗?如果你想让它工作,你需要大气弹簧的扩展。看看这里的代码
--Jeanfrancois已经这样做了。在spring中使用服务和dao时没有问题。但问题是当自动将春季服务连接到大气时。(上面的例子,NotificationChannelController属于大气,NotificationService来自Spring)宾果!Spring服务已自动连接,但出现了另一个问题。广播工厂这次无法自动连线/注入。错误:找不到依赖项类型为[org.atmosphere.cpr.BroadcasterFactory]的符合条件的bean:至少需要1个符合此依赖项autowire候选项条件的bean。依赖项注释:{@javax.inject.inject()}
<context:component-scan base-package="packagefolder" />
<context:annotation-config />
<context:load-time-weaver aspectj-weaving="on"/>
<!-- Atmosphere -->
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-jersey</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.atmosphere.client</groupId>
<artifactId>javascript</artifactId>
<version>2.2.4</version>
<type>war</type>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
<version>4.0.6.RELEASE</version>
</dependency>
<!-- Spring ORM Hibernate -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.0.6.RELEASE</version>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-acl</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<!-- @Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
-javaagent:"pathto/spring-instrument-4.0.6.RELEASE.jar"
@Controller
@RequestMapping("secured/*")
public class BaseController {
private static final Logger LOGGER = LoggerFactory
.getLogger(BaseController.class);
@RequestMapping(value = "test", method = RequestMethod.GET)
@ResponseBody
public void testMethod() throws Exception {
System.out.println("AAAAAAAAAAAAAAAAAA");
NotificationChannelController ncc = new NotificationChannelController();
ncc.show();
}
}
@ManagedService(path = "/notification/{channel: [a-zA-Z][a-zA-Z_0-9]*}")
@Singleton
@Configurable(preConstruction=true,dependencyCheck=true,autowire=Autowire.BY_TYPE)
public final class NotificationChannelController {
private final Logger logger = LoggerFactory.getLogger(NotificationChannelController.class);
private final ConcurrentHashMap<String, String> users = new ConcurrentHashMap<String, String>();
public void show(){
System.out.println("A");
for(String key : users.keySet()){
System.out.println(key + " " + users.get(key));
}
System.out.println("B");
for(String s : getRooms(factory.lookupAll())){
System.out.println(s);
}
System.out.println("C");
}
}