修改Webservice发布配置
This commit is contained in:
parent
107d1ad379
commit
d93494a9fc
|
|
@ -26,7 +26,7 @@ import org.springframework.context.annotation.Configuration;
|
|||
*
|
||||
* @author Administrator
|
||||
*/
|
||||
@Configuration
|
||||
//@Configuration
|
||||
public class MinaConfig {
|
||||
|
||||
/**
|
||||
|
|
@ -125,7 +125,7 @@ public class MinaConfig {
|
|||
}
|
||||
|
||||
/**
|
||||
* 开始运行socket服务
|
||||
* 开始运行socket服务,创建监听
|
||||
* @return
|
||||
*/
|
||||
@Bean(initMethod = "bind", destroyMethod = "unbind")
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ package com.ifish.config;
|
|||
import com.sun.xml.ws.transport.http.servlet.WSServletContextListener;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import javax.servlet.annotation.WebListener;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -15,15 +16,20 @@ import javax.servlet.ServletContextListener;
|
|||
*/
|
||||
public class MyWSServletContextListener implements ServletContextListener {
|
||||
|
||||
private static WSServletContextListener wsscl = null;
|
||||
|
||||
static {
|
||||
wsscl = new WSServletContextListener();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce) {
|
||||
WSServletContextListener wsscl = new WSServletContextListener();
|
||||
wsscl.contextInitialized(sce);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
wsscl.contextDestroyed(sce);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import org.springframework.context.annotation.ComponentScan.Filter;
|
|||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
|
||||
/**
|
||||
|
|
@ -18,6 +19,7 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
|||
*/
|
||||
@Configuration
|
||||
//@Import(MybatisConfig.class) //导入数据库文件配置
|
||||
@ImportResource("classpath:minaConfig.xml")
|
||||
@ComponentScan(basePackages = {"com.ifish.*"},
|
||||
excludeFilters = {
|
||||
@Filter(type = FilterType.ANNOTATION, value = EnableWebMvc.class)})
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServlet
|
|||
|
||||
@Override
|
||||
protected Class<?>[] getRootConfigClasses() {
|
||||
return new Class<?>[]{RootConfig.class, MybatisConfig.class, MinaConfig.class, applicationContext().getClass()};
|
||||
return new Class<?>[]{RootConfig.class, MybatisConfig.class};//applicationContext().getClass()
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -30,7 +30,7 @@ public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServlet
|
|||
|
||||
@Override
|
||||
protected String[] getServletMappings() {
|
||||
return new String[]{"/api/*"};
|
||||
return new String[]{"/"};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.ifish.controller;
|
||||
|
||||
import com.ifish.socket.webService.MyService;
|
||||
import javax.xml.ws.Endpoint;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Administrator
|
||||
*/
|
||||
@Controller
|
||||
public class Index {
|
||||
|
||||
@RequestMapping("/fabu")
|
||||
|
||||
public ModelAndView fabu() {
|
||||
|
||||
ModelAndView mv = new ModelAndView();
|
||||
mv.setViewName("index");
|
||||
Endpoint.publish("http://localhost:9001/Service/webService", new MyService());
|
||||
return mv;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -9,11 +9,13 @@ import org.quartz.spi.TriggerFiredBundle;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.scheduling.quartz.AdaptableJobFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Administrator
|
||||
*/
|
||||
@Component
|
||||
public class JobFactory extends AdaptableJobFactory {
|
||||
|
||||
@Autowired
|
||||
|
|
|
|||
|
|
@ -31,6 +31,12 @@ public class MinaServerHandler extends IoHandlerAdapter {
|
|||
@Autowired
|
||||
private ScheduleJob scheduleJob;
|
||||
|
||||
/**
|
||||
* 当接口中其他方法抛出异常未被捕获时触发此方法
|
||||
* @param session
|
||||
* @param cause
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
|
||||
cause.printStackTrace();
|
||||
|
|
@ -38,7 +44,7 @@ public class MinaServerHandler extends IoHandlerAdapter {
|
|||
}
|
||||
|
||||
/**
|
||||
* 服务端接收消息处理
|
||||
* 当接收到消息后被触发 ,服务端接收消息处理
|
||||
*/
|
||||
@Override
|
||||
public void messageReceived(IoSession session, Object message) throws Exception {
|
||||
|
|
@ -46,7 +52,7 @@ public class MinaServerHandler extends IoHandlerAdapter {
|
|||
}
|
||||
|
||||
/**
|
||||
* 客户端连接的会话创建
|
||||
* 当会话创建时被触发 ,客户端连接的会话创建
|
||||
*/
|
||||
@Override
|
||||
public void sessionCreated(IoSession session) throws Exception {
|
||||
|
|
@ -54,7 +60,7 @@ public class MinaServerHandler extends IoHandlerAdapter {
|
|||
}
|
||||
|
||||
/**
|
||||
* 客户端连接关闭
|
||||
* 当会话关闭时被触发 ,客户端连接关闭
|
||||
*/
|
||||
@Override
|
||||
public void sessionClosed(IoSession session) throws Exception {
|
||||
|
|
@ -106,7 +112,7 @@ public class MinaServerHandler extends IoHandlerAdapter {
|
|||
}
|
||||
|
||||
/**
|
||||
* 空闲超时,主动关闭客户端连接
|
||||
* 当会话空闲时被触发,空闲超时,主动关闭客户端连接
|
||||
*/
|
||||
@Override
|
||||
public void sessionIdle(IoSession session, IdleStatus status)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
package com.ifish.socket.config;
|
||||
|
||||
import com.ifish.helper.UserHelperI;
|
||||
import com.ifish.socket.model.JobGroup;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
|
@ -21,6 +22,7 @@ import org.quartz.impl.StdSchedulerFactory;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -35,7 +37,7 @@ public class ScheduleJob {
|
|||
@Autowired
|
||||
private JobFactory jobFactory;
|
||||
|
||||
@PostConstruct //初始化方法的注解方式 等同与init-method=init
|
||||
//@PostConstruct //初始化方法的注解方式 等同与init-method=init
|
||||
public void init() {
|
||||
try {
|
||||
//调度任务开启
|
||||
|
|
@ -102,7 +104,7 @@ public class ScheduleJob {
|
|||
/**
|
||||
* 关闭调度任务
|
||||
*/
|
||||
@PreDestroy //销毁方法的注解方式 等同于destory-method=destory222
|
||||
//@PreDestroy //销毁方法的注解方式 等同于destory-method=destory222
|
||||
public void shutdown() {
|
||||
try {
|
||||
//关闭任务
|
||||
|
|
|
|||
|
|
@ -51,4 +51,5 @@ public class MyService {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,15 @@ import javax.xml.ws.Endpoint;
|
|||
public class ServiceBean {
|
||||
|
||||
public ServiceBean() {
|
||||
Endpoint.publish("http://localhost:9001/Service/webService", new MyService());
|
||||
|
||||
}
|
||||
|
||||
public void init() {
|
||||
try {
|
||||
Endpoint.publish("http://localhost:9001/Service/webService", new MyService());
|
||||
System.out.println("MyService发布成功!");
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@
|
|||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
|
||||
<!-- webService -->
|
||||
<bean id="serviceBean" class="com.ifish.socket.webService.ServiceBean"></bean>
|
||||
<bean id="serviceBean" class="com.ifish.socket.webService.ServiceBean" init-method="init"></bean>
|
||||
<!-- 消息处理类 -->
|
||||
<bean id="someServer" class="com.ifish.socket.config.SomeServer"></bean>
|
||||
<!-- 实现job中注入bean -->
|
||||
<!--<bean name="jobFactory" class="com.ifish.socket.config.JobFactory"/>-->
|
||||
<bean name="jobFactory" class="com.ifish.socket.config.JobFactory"/>
|
||||
<!-- 调度任务 -->
|
||||
<!--<bean id="scheduleJob" init-method="init" destroy-method="shutdown" class="com.ifish.socket.config.ScheduleJob"></bean>-->
|
||||
<bean id="scheduleJob" init-method="init" destroy-method="shutdown" class="com.ifish.socket.config.ScheduleJob"></bean>
|
||||
|
||||
<!-- 自定义的serverHandler -->
|
||||
<bean id="serverHandler" class="com.ifish.socket.config.MinaServerHandler"></bean>
|
||||
|
|
@ -68,7 +68,7 @@
|
|||
<property name="maxReadBufferSize" value="1024" />
|
||||
</bean>
|
||||
|
||||
<!-- 开始运行socket服务 -->
|
||||
<!-- 开始运行socket服务,创建监听 -->
|
||||
<bean id="ioAcceptor" class="org.apache.mina.transport.socket.nio.NioSocketAcceptor"
|
||||
init-method="bind" destroy-method="unbind">
|
||||
<property name="defaultLocalAddress" value="#{address.socketAddress}" />
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<endpoints version="2.0" xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime">
|
||||
<endpoint implementation="com.ifish.socket.webService.MyService" name="MyServiceService" url-pattern="/MyServiceService"/>
|
||||
</endpoints>
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<%@page contentType="text/html" pageEncoding="UTF-8"%>
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
||||
"http://www.w3.org/TR/html4/loose.dtd">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<title>Socket</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1 style="text-align: center">访问正常!</h1>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
|
||||
<listener>
|
||||
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
|
||||
</listener>
|
||||
<servlet>
|
||||
<servlet-name>MyServiceService</servlet-name>
|
||||
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>MyServiceService</servlet-name>
|
||||
<url-pattern>/MyServiceService</url-pattern>
|
||||
</servlet-mapping>
|
||||
<session-config>
|
||||
<session-timeout>
|
||||
30
|
||||
</session-timeout>
|
||||
</session-config>
|
||||
</web-app>
|
||||
Loading…
Reference in New Issue