springboot 1.4 CXF配置
启动类:
package com.eshore.main; import org.apache.catalina.connector.Connector;
import org.apache.coyote.http11.Http11NioProtocol;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource; @ImportResource(value = { "classpath:applicationContext.xml" })
@SpringBootApplication
public class SpringBootStarter implements EmbeddedServletContainerCustomizer{
private static final Logger logger = LoggerFactory.getLogger(SpringBootStarter.class);
private static final int CXF_PORT = 9090; public static void main(String[] args) {
SpringApplication.run(SpringBootStarter.class, args);
} @Bean
public ServletRegistrationBean servletRegistrationBean() {
return new ServletRegistrationBean(new CXFServlet(), "/services/*");
}
/*
* 设置启动端口号
*/
public void customize(ConfigurableEmbeddedServletContainer container) {
container.setPort(CXF_PORT);
TomcatEmbeddedServletContainerFactory tomcatFactory = (TomcatEmbeddedServletContainerFactory)container;
tomcatFactory.addConnectorCustomizers(new MyTomcatConnectorCustomizer());
} class MyTomcatConnectorCustomizer implements TomcatConnectorCustomizer
{
public void customize(Connector connector)
{
Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
//设置最大连接数
protocol.setMaxConnections(2800);
//设置最大线程数
protocol.setMaxThreads(2800);
protocol.setConnectionTimeout(40000);
}
}
}
接口类:
package com.eshore.db.webservice; import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService; import com.eshore.db.SendDto; @WebService
public interface ServerSendSmsService { @WebMethod
String sendSms(SendDto sms); @WebMethod
String getState(@WebParam(name = "requestId") String requestId); }
实现类:
package com.eshore.db.webservice; import javax.jws.WebService; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import com.eshore.db.SendDto;
import com.eshore.db.SmsService;
import com.eshore.message.SmsMessage;
import com.eshore.sender.ServiceSender;
import com.eshore.util.MD5Crypter;
@WebService(endpointInterface="com.eshore.db.webservice.ServerSendSmsService",serviceName="ServerSendSmsService")
public class ServerSendSmsServiceImpl implements ServerSendSmsService{
private Logger log=LoggerFactory.getLogger(this.getClass());
@Autowired
private ServiceSender sender;
@Autowired
private SmsService smsService; @Override
public String sendSms(SendDto dto) {
log.info("receive message :{}",dto.toString());
String requestId="";
SmsMessage msg=new SmsMessage();
msg.setContent(dto.getContent());
msg.setReceivers(dto.getReceivers());
msg.setSender(dto.getSender());
msg.setContent(dto.getContent());
String originalString=String.valueOf(System.currentTimeMillis())+dto.getContent();
requestId=MD5Crypter.MD5Encode(originalString);
msg.setMessageId(requestId);
//sender.send(msg);
log.info("requestId:{}",requestId);
log.info("controller save message...");
requestId="it's a test";
return requestId;
} @Override
public String getState(String requestId) {
return "getstateTest";
//return smsService.queryByRequestId(requestId);
} }
配置文件:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"
default-autowire="byName" default-lazy-init="true">
<description>基于Apache CXF的Web Service配置文件</description> <import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<!-- 发送短信 -->
<jaxws:endpoint id="ServerSendSmsService" address="/ServerSendSmsService">
<jaxws:implementor>
<ref bean="serverSendSmsServiceImpl" />
</jaxws:implementor>
</jaxws:endpoint>
<bean id="serverSendSmsServiceImpl"
class="com.eshore.db.webservice.ServerSendSmsServiceImpl" />
</beans>
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="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/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<import resource="classpath*:applicationContext-cxf.xml"/>
<context:component-scan base-package="com.eshore.*" />
<task:annotation-driven />
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config.properties</value>
</list>
</property>
</bean>
<!-- 配置数据源 -->
<bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="url" value="${jdbc_url}" />
<property name="username" value="${jdbc_username}" />
<property name="password" value="${jdbc_password}" />
<property name="initialSize" value="10" />
<property name="maxActive" value="60" />
<property name="minIdle" value="20" />
<property name="maxWait" value="60000" />
<property name="poolPreparedStatements" value="true" />
<property name="maxPoolPreparedStatementPerConnectionSize" value="33" />
<property name="validationQuery" value="${validationQuery}" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="testWhileIdle" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<property name="minEvictableIdleTimeMillis" value="25200000" />
<property name="removeAbandoned" value="false" />
<property name="removeAbandonedTimeout" value="1800" />
<property name="logAbandoned" value="true" />
<!-- <property name="filters" value="stat" /> -->
</bean> <!-- JDBC模版 -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean> <bean class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.eshore" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
</bean>
</property>
</bean> <!-- 配置 JPA Transaction -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"></bean>
</property>
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<!-- 配置 Annotation 驱动,定义事务-->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" /> </beans>
springboot 1.4 CXF配置的更多相关文章
- springboot 入门八-自定义配置信息(编码、拦截器、静态资源等)
若想实际自定义相关配置,只需要继承WebMvcConfigurerAdapter.WebMvcConfigurerAdapter定义些空方法用来重写项目需要用到的WebMvcConfigure实现.具 ...
- springboot情操陶冶-web配置(九)
承接前文springboot情操陶冶-web配置(八),本文在前文的基础上深入了解下WebSecurity类的运作逻辑 WebSecurityConfigurerAdapter 在剖析WebSecur ...
- springboot情操陶冶-web配置(七)
参数校验通常是OpenApi必做的操作,其会对不合法的输入做统一的校验以防止恶意的请求.本文则对参数校验这方面作下简单的分析 spring.factories 读者应该对此文件加以深刻的印象,很多sp ...
- springboot情操陶冶-web配置(四)
承接前文springboot情操陶冶-web配置(三),本文将在DispatcherServlet应用的基础上谈下websocket的使用 websocket websocket的简单了解可见维基百科 ...
- springboot情操陶冶-web配置(二)
承接前文springboot情操陶冶-web配置(一),在分析mvc的配置之前先了解下其默认的错误界面是如何显示的 404界面 springboot有个比较有趣的配置server.error.whit ...
- springboot情操陶冶-web配置(三)
承接前文springboot情操陶冶-web配置(二),本文将在前文的基础上分析下mvc的相关应用 MVC简单例子 直接编写一个Controller层的代码,返回格式为json package com ...
- springboot+ibatis 多数据源配置
这个是boot基本版本包,因为我用的打包方式是war所以去除掉了boot内置的tomcat,但是为了方便测试又引入了内置tomcat,只要添加<scope>provided</sco ...
- SpringBoot修改Servlet相关配置
第一种方式在配置文件中进行修改 server.port=8081 server.servlet.context-path=/springboot server.tomcat.uri-encoding= ...
- SpringBoot扩展SpringMVC自动配置
SpringBoot中自动配置了 ViewResolver(视图解析器) ContentNegotiatingViewResolver(组合所有的视图解析器) 自动配置了静态资源文件夹.静态首页.fa ...
随机推荐
- 零零总总遇到过的CSS 样式
1:添加弹出框阴影 2:禁止文本域缩放 3:直接使用CSS 完成文本内容大小写(针对英文) 4: 文本框中的占位符 5:让table每列一样高 6:不使用js 让内容换行 word-break 7:曾 ...
- Python 3 行代码 5 秒抠图的 AI 神器,根本无需 PS
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: 苏克1900 PS:如有需要Python学习资料的小伙伴可以加点击下 ...
- Linux网络——配置网络之iproute家族命令
Linux网络——配置网络之iproute家族命令 摘要:本文主要学习了iproute家族用来配置网络的命令. ip命令 ip命令用于查看和管理IP地址.接口.路由.隧道等.用来取代ifconfig命 ...
- PHP面试题2019年小米工程师面试题及答案解析
一.单选题(共29题,每题5分) 1.PHP面向对象方法重写描述错误的是? A.子类必须继承父类 B.子类可以重写父类已有方法 C.重写之后子类会调用父类方法 D.子类也可以具有与父类同名的属性,进行 ...
- dependencies和devDependencies区别
vue-cli3.x项目的package.json中,有两种依赖: dependencies:项目依赖.在编码阶段和呈现页面阶段都需要的,也就是说,项目依赖即在开发环境中,又在生产环境中.如js框架v ...
- ES6箭头函数-2
以下来文字来自阮大神所著书籍摘记.为了加深记忆.本人就手动敲了一遍(相关代码本人也执行过,可保证运行通过.) 箭头函数注意事项: 1) 函数体内的this对象就是定义时所在的对象,而不是使用时所在的对 ...
- 教你如何添加Xcode 9.3配置包?(安装流程可供其他版本安装参考)
1.准备好你想要的Xcode版本的安装包 ,这里以Xcode 9.3为例. → 2.打开Xcode开发工具的安装路径 ...
- JDK10源码分析之HashMap
HashMap在工作中大量使用,但是具体原理和实现是如何的呢?技术细节是什么?带着很多疑问,我们来看下JDK10源码吧. 1.数据结构 采用Node<K,V>[]数组,其中,Node< ...
- TICK技术栈(一)TICK技术栈介绍
1.什么是TICK技术栈? 1.1 简介 TICK 是由 InfluxData开发的一套开源工具栈,由 Telegraf, InfluxDB, Chronograf, Kapacitor 四个工具的首 ...
- SQL server 2012 各个版本比较
有关不同版本的 SQL Server 2012 所支持的功能的详细信息. 功能名称 Enterprise 商业智能 Standard Web Express with Advanced Service ...