我是靠谱客的博主 坚定白开水,这篇文章主要介绍基于Rribbit和Spring MVC搭建REST风格架构,现在分享给大家,希望可以做个参考。

基于Rribbit事件驱动和Spring MVC搭建Restful风格的架构步骤 :

 

配置Pom:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.wx</groupId> <artifactId>sipbus</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>sipbus Maven Webapp</name> <url>http://maven.apache.org</url> <build> <plugins> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>6.1.19</version> <configuration> <scanIntervalSeconds>10</scanIntervalSeconds> <contextPath>sipbus</contextPath> <connectors> <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector"> <port>7000</port> <maxIdleTime>60000</maxIdleTime> </connector> </connectors> </configuration> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <configuration> <webappDirectory>${project.build.directory}/bin/sipbus.war </webappDirectory> <useCache>false</useCache> <dependentWarExcludes>WEB-INF/lib/*-1.0-SNAPSHOT* </dependentWarExcludes> </configuration> </plugin> <plugin> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${basedir}/src/main/webapp/WEB-INF/lib </outputDirectory> </configuration> </execution> </executions> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.rribbit</groupId> <artifactId>rribbit</artifactId> <version>2.7.0</version> <type>jar</type> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>3.1.2.RELEASE</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>3.1.2.RELEASE</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>3.1.2.RELEASE</version> <type>jar</type> <scope>compile</scope> </dependency> </dependencies> </project>

 

Rribbit配置:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <bean id="creator" class="org.rribbit.creation.SpringBeanClassBasedListenerObjectCreator"> <property name="packageNames"> <list> <value>com.geone.its</value> </list> </property> <property name="scanSubpackages" value="true" /> </bean> <bean id="rrb" class="org.rribbit.util.RRiBbitUtil" factory-method="createRequestResponseBusForLocalUse"> <constructor-arg ref="creator" /> <constructor-arg value="true" /> </bean> </beans>

 

Spring MVC配置:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?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: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.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <import resource="classpath*:rribbit-context.xml" /> <context:annotation-config /> <context:component-scan base-package="com.wx" /> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> </beans>

 

Rribbit测试类:

复制代码
1
2
3
4
5
6
7
8
@Service("testRribbit") public class TestRribbit { @Listener(hint = "testEvent") public void testEvent() { System.out.println("******rribbit********"); } }

 

Rest测试类:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
@Controller @RequestMapping("/test") public class TestRest { @Autowired private RequestResponseBus rrb; @RequestMapping("/hello.do") public void printWelcome(ModelMap model) { model.addAttribute("message", "testing"); System.out.println("*************testing**********"); rrb.send("testEvent"); } }

 

执行mvn package

mvn jetty:run

 

visit url:http://localhost:7000/testRest/test/hello

 

信息: FrameworkServlet 'springMvc': initialization completed in 462 ms

*************testing**********

******rribbit********

最后

以上就是坚定白开水最近收集整理的关于基于Rribbit和Spring MVC搭建REST风格架构的全部内容,更多相关基于Rribbit和Spring内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(76)

评论列表共有 0 条评论

立即
投稿
返回
顶部