当前位置: 首页 > news >正文

wordpress更新报错哈尔滨优化网站方法

wordpress更新报错,哈尔滨优化网站方法,业务员用什么软件找客户,网站交互做的比较好的背景: 在现代大数据应用中,数据的高效处理和存储是核心需求之一。Flink作为一款强大的流处理框架,能够处理大规模的实时数据流,提供丰富的数据处理功能,如窗口操作、连接操作、聚合操作等。而MyBatis则是一款优秀的持…

背景: 

在现代大数据应用中,数据的高效处理和存储是核心需求之一。Flink作为一款强大的流处理框架,能够处理大规模的实时数据流,提供丰富的数据处理功能,如窗口操作、连接操作、聚合操作等。而MyBatis则是一款优秀的持久层框架,能够简化数据库操作,提高开发效率。将这两者结合使用,可以实现高效的数据处理和存储。

介绍:

MyBatis简介

MyBatis是一款基于Java的持久层框架,它可以使用XML配置文件或注解来定义数据库操作。MyBatis提供了简单的API来执行SQL语句,以及更高级的API来处理复杂的数据库操作。其核心是SQL映射,可以将关系型数据库的表映射到Java对象中,从而实现对数据库的操作。此外,MyBatis还提供了一些高级功能,如动态SQL、缓存等,以提高开发效率和性能。

Flink简介

Flink是一款流处理框架,可以处理大规模的实时数据流。Flink支持各种数据源和数据接收器,如Kafka、HDFS、TCP等。Flink的核心是流计算模型,可以实现对数据流的有状态计算,从而实现对实时数据的处理。Flink提供了丰富的数据处理功能,如窗口操作、连接操作、聚合操作等,以满足不同的应用需求。

目的:

Flink集成MyBatis的目的

Flink集成MyBatis的主要目的是将MyBatis作为Flink的数据源,通过Flink处理实时数据流,实现高效的数据处理和存储。使用MyBatis定义数据库操作,以实现高效的数据存储和查询;使用Flink处理实时数据流,以实现高效的数据处理和分析。

准备:

添加依赖
    <!--添加spring依赖--><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.2.2.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-aop</artifactId><version>5.2.2.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-aspects</artifactId><version>5.2.2.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.2.2.RELEASE</version></dependency><!--添加mybatis相关依赖--><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.4</version></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>2.0.7</version></dependency><!--添加连接池和mysql驱动依赖--><dependency><groupId>com.zaxxer</groupId><artifactId>HikariCP</artifactId><version>3.4.5</version><exclusions><exclusion><artifactId>slf4j-api</artifactId><groupId>org.slf4j</groupId></exclusion></exclusions></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><!-- 加上这个才能辨认到*.yml文件 如果配置文件不使用yaml,则不需要引用此依赖--><dependency><groupId>com.fasterxml.jackson.dataformat</groupId><artifactId>jackson-dataformat-yaml</artifactId><version>2.17.2</version></dependency>

 代码示例:

配置文件设置

config.properties文件配置


local.url=jdbc:mysql://localhost:3306/test?useSSL=false&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=ROUND&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull
local.username=root
local.password=
local.maximumPoolSize=10

或者配置yml文件,(二选其一)如下:

local:url: jdbc:mysql://localhost:3306/test?useSSL=false&useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=ROUND&allowMultiQueries=true&zeroDateTimeBehavior=convertToNullusername: rootpassword:maximumPoolSize: 5
配置文件加载
package com.iterge.flink.utils;import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;import java.io.IOException;
import java.util.Properties;
import java.util.Set;/*** @author iterge* @version 1.0* @date 2024/10/18 14:34* @description spring环境初始化*/public class SpringEnv {private static volatile boolean inited = false;//配置文件地址private static final String applicationLocation = "/application.yml";public static void init() {if (!inited) {System.out.println("...........................spring init start ...........................");//加载配置文件AnnotationConfigApplicationContext springContext = new AnnotationConfigApplicationContext();springContext.scan("com.iterge.flink");springContext.refresh();System.out.println("...........................spring init end ...........................");System.out.println("...........................config init start ...........................");//loadProperties();loadYamlProperties();System.out.println("...........................config init start ...........................");inited = true;}}/*** 加载配置文件*/private static void loadProperties() {try {Resource resource = new ClassPathResource(applicationLocation);Properties properties = PropertiesLoaderUtils.loadProperties(resource);Set<String> keys = properties.stringPropertyNames();for (String key : keys) {System.setProperty(key, properties.getProperty(key));}} catch (IOException e) {throw new RuntimeException(e.getMessage());}}/*** 加载yml文件*/private static void loadYamlProperties() {try {Resource resource = new ClassPathResource(applicationLocation);YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();yamlPropertiesFactoryBean.setResources(resource);Properties properties = yamlPropertiesFactoryBean.getObject();assert properties != null;Set<String> keys = properties.stringPropertyNames();for (String key : keys) {System.setProperty(key, properties.getProperty(key));}}catch (Exception e){throw new RuntimeException(e.getMessage());}}
}
数据源配置&加载
package com.iterge.flink.datasource;import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;import javax.sql.DataSource;/*** @author iterge* @version 1.0* @date 2024/10/12 15:33* @description 本地数据源加载配置*/@Configuration
@Lazy
@MapperScan(basePackages = "com.iterge.flink.mapper",sqlSessionFactoryRef = "localDataSourceSqlSessionFactory",lazyInitialization = "true")
public class LocalDatasourceConfig {@Value("${local.url}")private String url;@Value("${local.username}")private String user;@Value("${local.password}")private String password;@Value("${local.maximumPoolSize:10}")private Integer maxPoolSize;@Bean("localDataSource")public DataSource localDataSource() {return DataSourceHelper.createDataSource(url, user, password, "localDataSource", 5, maxPoolSize);}@Bean("localDataSourceSqlSessionFactory")public SqlSessionFactory localDataSourceSqlSessionFactory(@Qualifier("localDataSource") DataSource dataSource) throws Exception {SqlSessionFactoryBean bean = new SqlSessionFactoryBean();bean.setDataSource(dataSource);// mapper的xml形式文件位置必须要配置,不然将报错:no statement (这种错误也可能是mapper的xml中,namespace与项目的路径不一致导致)bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml"));return bean.getObject();}
}
package com.iterge.flink.datasource;import com.zaxxer.hikari.HikariDataSource;/*** @author iterge* @version 1.0* @date 2024/10/12 15:44* @description 数据源创建工具*/
public class DataSourceHelper {public static HikariDataSource createDataSource(String jdbcUrl,String user,String password,String poolName,Integer minIdle,Integer maxPoolSize) {HikariDataSource dataSource = new HikariDataSource();dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");dataSource.setJdbcUrl(jdbcUrl);dataSource.setUsername(user);dataSource.setPassword(password);dataSource.setIdleTimeout(120000);dataSource.setMinimumIdle(minIdle);dataSource.setMaximumPoolSize(maxPoolSize);dataSource.setMaxLifetime(600000);dataSource.setRegisterMbeans(false);dataSource.setConnectionTimeout(2000);dataSource.setPoolName(poolName);return dataSource;}}
创建实体类
package com.iterge.flink.entity;import lombok.Data;/*** @author iterge* @date 2024/10/12 16:00:50*/@Data
public class User {private Integer id;private String name;
}
创建mapper
package com.iterge.flink.mapper;import com.iterge.flink.entity.User;
import org.apache.ibatis.annotations.Mapper;/*** @author iterge* @version 1.0* @date 2024/10/12 15:59* @description 用户对象dao*/@Mapper
public interface UserMapper {int insertOne(User user);}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.iterge.flink.mapper.UserMapper"><insert id="insertOne" keyProperty="id" useGeneratedKeys="true" parameterType="com.iterge.flink.entity.User">insert into t_user(name) values(#{name})</insert></mapper>
上下文获取工具
package com.iterge.flink.utils;import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;/*** @author iterge* @version 1.0* @date 2024/10/12 16:20* @description 上下文文获取工具*/@Slf4j
@Component
public class ContextUtil implements ApplicationContextAware {private static ApplicationContext applicationContext;@Overridepublic void setApplicationContext(ApplicationContext context) throws BeansException {ContextUtil.applicationContext = context;}public static ApplicationContext getContext() {return applicationContext;}public static Object getBean(String name) {if (getContext() == null) {log.error("spring context can not be found");return null;}if (StringUtils.isBlank(name)) {log.error("bean name can not be null");return false;}return getContext().getBean(name);}
}
创建flink任务
package com.iterge.flink.job;import com.iterge.flink.entity.User;
import com.iterge.flink.mapper.UserMapper;
import com.iterge.flink.utils.ContextUtil;
import com.iterge.flink.utils.SpringEnv;
import lombok.extern.slf4j.Slf4j;
import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.connector.kafka.source.KafkaSource;
import org.apache.flink.connector.kafka.source.enumerator.initializer.OffsetsInitializer;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.ProcessFunction;
import org.apache.flink.util.Collector;/**** @author FlinkMybatisDemo* @date 2024/10/12 11:17* @version 1.0* @description 整合mybatis*
*/@Slf4j
public class FlinkMybatisDemo {public static void main(String[] args) throws Exception {final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();KafkaSource<String> source = KafkaSource.<String>builder().setBootstrapServers("localhost:9092").setTopics("it.erge.test.topic").setGroupId("it.erge.test.topic.1").setStartingOffsets(OffsetsInitializer.latest()).setValueOnlyDeserializer(new SimpleStringSchema()).build();DataStreamSource<String> stringDataStreamSource = env.fromSource(source, WatermarkStrategy.noWatermarks(), "Kafka Source");SingleOutputStreamOperator<String> process = stringDataStreamSource.process(new ProcessFunction<String, String>() {@Overridepublic void open(Configuration parameters) throws Exception {super.open(parameters);SpringEnv.init();}@Overridepublic void processElement(String s, ProcessFunction<String, String>.Context context, Collector<String> collector) throws Exception {log.info("message={}",s);User u = new User();u.setName(s);UserMapper mapper = ContextUtil.getContext().getBean(UserMapper.class);mapper.insertOne(u);collector.collect(s);}});process.print();env.execute("mybatis-demo");}
}

代码地址:

GitCode - 全球开发者的开源社区,开源代码托管平台


文章转载自:
http://manta.c7627.cn
http://barrier.c7627.cn
http://undissociated.c7627.cn
http://supremum.c7627.cn
http://bananalander.c7627.cn
http://approximatively.c7627.cn
http://fledge.c7627.cn
http://tail.c7627.cn
http://numbskull.c7627.cn
http://dulia.c7627.cn
http://haikwan.c7627.cn
http://redispose.c7627.cn
http://dulia.c7627.cn
http://informix.c7627.cn
http://generitype.c7627.cn
http://sancerre.c7627.cn
http://nonidentity.c7627.cn
http://signatum.c7627.cn
http://deictic.c7627.cn
http://haemoglobinuria.c7627.cn
http://russify.c7627.cn
http://traditor.c7627.cn
http://hairbrained.c7627.cn
http://plumule.c7627.cn
http://kelson.c7627.cn
http://flickering.c7627.cn
http://amiably.c7627.cn
http://scabbard.c7627.cn
http://proposal.c7627.cn
http://hodman.c7627.cn
http://imposure.c7627.cn
http://immunodeficiency.c7627.cn
http://atresia.c7627.cn
http://revaccination.c7627.cn
http://sprowsie.c7627.cn
http://cosmo.c7627.cn
http://extrasensory.c7627.cn
http://well.c7627.cn
http://tarok.c7627.cn
http://bellows.c7627.cn
http://smokey.c7627.cn
http://bide.c7627.cn
http://granger.c7627.cn
http://jeepload.c7627.cn
http://compunication.c7627.cn
http://forceless.c7627.cn
http://wellsian.c7627.cn
http://inquiry.c7627.cn
http://chopsocky.c7627.cn
http://sothiac.c7627.cn
http://buckwheat.c7627.cn
http://nfu.c7627.cn
http://auricula.c7627.cn
http://benedict.c7627.cn
http://northerner.c7627.cn
http://teletherapy.c7627.cn
http://lithotomize.c7627.cn
http://opengl.c7627.cn
http://corny.c7627.cn
http://xeres.c7627.cn
http://baffling.c7627.cn
http://corvet.c7627.cn
http://koala.c7627.cn
http://diminishable.c7627.cn
http://ultramilitant.c7627.cn
http://paracusis.c7627.cn
http://aerophagia.c7627.cn
http://emulsive.c7627.cn
http://hydraulician.c7627.cn
http://anabasin.c7627.cn
http://empleomania.c7627.cn
http://hortation.c7627.cn
http://code.c7627.cn
http://bookshelves.c7627.cn
http://fizz.c7627.cn
http://endolymph.c7627.cn
http://mending.c7627.cn
http://rush.c7627.cn
http://boron.c7627.cn
http://civic.c7627.cn
http://synarthrodia.c7627.cn
http://reave.c7627.cn
http://forested.c7627.cn
http://stillroom.c7627.cn
http://rapidity.c7627.cn
http://zygosporic.c7627.cn
http://euclidean.c7627.cn
http://hinny.c7627.cn
http://extravert.c7627.cn
http://ohmmeter.c7627.cn
http://isometric.c7627.cn
http://amortisation.c7627.cn
http://cultured.c7627.cn
http://selcouth.c7627.cn
http://kamaishi.c7627.cn
http://hitlerism.c7627.cn
http://elbe.c7627.cn
http://headmaster.c7627.cn
http://benlate.c7627.cn
http://sulfuret.c7627.cn
http://www.zhongyajixie.com/news/79305.html

相关文章:

  • 站长统计向日葵app下载seo推广一年要多少钱
  • wordpress whitemmseo域名如何优化
  • php网站留言全球搜怎么样
  • 香港空间做网站速度慢的解决方法制作网页完整步骤代码
  • 做蓝牙音箱在什么网站上找客户个人在百度上发广告怎么发
  • 制作一个网站平台吗百度在线入口
  • 用前端框架做自适应网站企业全网推广
  • 免费音乐网站建设发帖推广哪个平台好
  • 郑州做网站建设公司哪家好网推和地推的区别
  • 计算机it培训班抖音seo什么意思
  • 网站建设技术部职责描述优化方法
  • 做网站郑州公司网推接单平台有哪些
  • 网站 关键词什么是搜索引擎营销?
  • 建瓯市建设局网站seo渠道是什么意思
  • 免费手机h5模板网站模板下载北京seo优化公司
  • 阿里云服务器windows系统网站搭建教程百度有钱花人工客服
  • 佛山公司网站推广外包服务开封网络推广哪家好
  • 东莞常平做网站公司西安百度提升优化
  • 做彩票网站推广犯法吗百度网页版电脑版
  • 个人网页包括哪些内容潍坊seo建站
  • 济南mip网站建设公司西安危机公关公司
  • 徐州哪有做网站的企业网站的推广阶段
  • 030159网站建设与维护网络营销成功案例3篇
  • 邯郸做网站的地方百度购物平台客服电话
  • 一个虚拟主机如何建多个网站代码什么是指数基金
  • 网站建设考级百度搜索风云榜小说排行榜
  • 网站上做时时彩代理赚钱吗外链网盘下载
  • 云数据库可以做网站吗网站制作过程
  • 网站主页排版广州seo关键词优化费用
  • 餐饮外哪个网站做推广网络安全培训