首页 文章 精选 留言 我的

精选列表

搜索[WSL集成],共10005篇文章
优秀的个人博客,低调大师

CDH集成kafka

添加kafka(把包放到cm主机目录) 1.下载kafka包http://archive.cloudera.com/kafka/parcels/latest/ 把包放到parcel-repo 目录 2.下载csd包http://archive.cloudera.com/csds/kafka/ 放到csd目录 3.分配kafka包并激活 注意:如果进度卡在“已解压”,直接返回重新进来就会看到“激活” 4添加kafka角色 可根据需求填写各选项(我这里直接默认) 以下是容易踩坑的 安装后启动报错“Java heap space” 需要在cdh控制台上修改Java内存,默认50M,安装时也没提示让设置内存大小,结果自动安装后到最后的启动阶段报错(如下图) 这个时候可以返回到首页,点击kafka,进入“配置”修改java内存 找到Java Heap Size 改为1G(根据服务器配置改参数) 最后控制台重启kafka就可以了

优秀的个人博客,低调大师

Springboot集成MongoDB

简介 MongoDB(来自于英文单词“Humongous”,中文含义为“庞大”)是可以应用于各种规模的企业、各个行业以及各类应用程序的开源数据库。作为一个适用于敏捷开发的数据库,MongoDB的数据模式可以随着应用程序的发展而灵活地更新。与此同时,它也为开发人员 提供了传统数据库的功能:二级索引,完整的查询系统以及严格一致性等等。 MongoDB能够使企业更加具有敏捷性和可扩展性,各种规模的企业都可以通过使用MongoDB来创建新的应用,提高与客户之间的工作效率,加快产品上市时间,以及降低企业成本。 安装mongoDB https://www.cnblogs.com/woshimrf/p/linux-install-mongodb.html 创建项目 https://github.com/Ryan-Miao/springboot-with-mongodb pom <?xml version="1.0" encoding="UTF-8"?> <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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.test</groupId> <artifactId>springboot-with-mongodb</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>springboot-with-mongodb</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.7.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.7.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 配置文件 spring.data.mongodb.uri=mongodb://localhost:27017/demo 创建一个表/集合 一个消费者 @Data public class Customer { @Id public String id; public String firstName; public String lastName; private List<Hobby> hobbies; public Customer() { } public Customer(String firstName, String lastName, List<Hobby> hobbies) { this.firstName = firstName; this.lastName = lastName; this.hobbies = hobbies; } } import org.springframework.data.annotation.Id; 是mongodb里的主键 创建Repository JPA的一个特性就是简化了CRUD, 通过解析方法名实现数据的传输 import com.test.springbootwithmongodb.entity.Customer; import java.util.List; import org.springframework.data.mongodb.repository.MongoRepository; public interface CustomerRepository extends MongoRepository<Customer, String> { Customer findByFirstName(String firstName); List<Customer> findByLastName(String lastName); } 方法名findBy字段名即可实现查询。 启动并测试 @SpringBootApplication public class SpringbootWithMongodbApplication implements CommandLineRunner { private final CustomerRepository repository; private final BookRepository bookRepository; private final AuthorRepository authorRepository; @Autowired public SpringbootWithMongodbApplication(CustomerRepository repository, BookRepository bookRepository, AuthorRepository authorRepository) { this.repository = repository; this.bookRepository = bookRepository; this.authorRepository = authorRepository; } public static void main(String[] args) { SpringApplication.run(SpringbootWithMongodbApplication.class, args); } @Override public void run(String... args) { repository.deleteAll(); // save a couple of customers repository.save(new Customer("Alice", "Smith", Lists.newArrayList(new Hobby("读书", 1), new Hobby("看电影", 2)))); repository.save(new Customer("Bob", "Smith", Lists.newArrayList())); // fetch all customers System.out.println("Customers found with findAll():"); System.out.println("-------------------------------"); for (Customer customer : repository.findAll()) { System.out.println(customer); } System.out.println(); // fetch an individual customer System.out.println("Customer found with findByFirstName('Alice'):"); System.out.println("--------------------------------"); System.out.println(repository.findByFirstName("Alice")); System.out.println("Customers found with findByLastName('Smith'):"); System.out.println("--------------------------------"); for (Customer customer : repository.findByLastName("Smith")) { System.out.println(customer); } } } 至此,hello world完成。基本实现了mongoDB持久层的工作,只要继续深入开发即可。 关联表 创建一个书籍的集合 import java.time.LocalDate; import lombok.Data; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Field; @Data @Document(collection = "books") public class Book { @Id private String id; private String title; @Field("published") private LocalDate publicationDate; // No args Constructor public Book(String title, LocalDate publicationDate) { this.title = title; this.publicationDate = publicationDate; } } @Field指定数据库映射的字段 @Transient标注的字段则不会映射到db @Document(collection = "books")可以指定集合名称,如果不指定则是类名首字母小写 创建一个作者,作者拥有书籍 @Data public class Author { @Id private ObjectId id; @Indexed(unique = true) private String name; @DBRef private Set<Book> books; // No args Constructor public Author(String name) { this.name = name; } } @DBRef会引用books的表 @Indexed(unique = true)设置索引,并且是唯一性索引 CRUD 暂时不自定义查询了,利用内置的查询即可 public interface AuthorRepository extends MongoRepository<Author, ObjectId> { } public interface BookRepository extends MongoRepository<Book, ObjectId> { } 测试 bookRepository.deleteAll(); authorRepository.deleteAll(); Book ci = new Book("Continous Integration", LocalDate.now()); // id will be generated after save bookRepository.save(ci); Book c2 = new Book("Java编程思想", LocalDate.now()); Book c3 = new Book("Java核心技术", LocalDate.now()); Book c4 = new Book("Effective Java", LocalDate.now()); Book c5 = new Book("深入理解虚拟机", LocalDate.now()); Book c6 = new Book("深入理解虚拟机", LocalDate.now()); bookRepository.save(c2); bookRepository.save(c3); bookRepository.save(c4); bookRepository.save(c5); bookRepository.save(c6); List<Book> books = bookRepository.findAll(); System.out.println(books); Author julius = new Author("Julius"); julius.setBooks(Stream.of(ci, c2, c3, c4, c5, c6).collect(Collectors.toSet())); authorRepository.save(julius); System.out.println(authorRepository.findAll()); 启动可以看到控制台输出: [Book(id=5b0bec767a49d017f0e46c63, title=Continous Integration, publicationDate=2018-05-28), Book(id=5b0bec767a49d017f0e46c64, title=Java编程思想, publicationDate=2018-05-28), Book(id=5b0bec767a49d017f0e46c65, title=Java核心技术, publicationDate=2018-05-28), Book(id=5b0bec767a49d017f0e46c66, title=Effective Java, publicationDate=2018-05-28), Book(id=5b0bec767a49d017f0e46c67, title=深入理解虚拟机, publicationDate=2018-05-28), Book(id=5b0bec767a49d017f0e46c68, title=深入理解虚拟机, publicationDate=2018-05-28)] [Author(id=5b0bec767a49d017f0e46c69, name=Julius, books=[Book(id=5b0bec767a49d017f0e46c64, title=Java编程思想, publicationDate=2018-05-28), Book(id=5b0bec767a49d017f0e46c68, title=深入理解虚拟机, publicationDate=2018-05-28), Book(id=5b0bec767a49d017f0e46c67, title=深入理解虚拟机, publicationDate=2018-05-28), Book(id=5b0bec767a49d017f0e46c63, title=Continous Integration, publicationDate=2018-05-28), Book(id=5b0bec767a49d017f0e46c65, title=Java核心技术, publicationDate=2018-05-28), Book(id=5b0bec767a49d017f0e46c66, title=Effective Java, publicationDate=2018-05-28)])] 连接db,查询 db.author.find({}) { "_id" : ObjectId("5b0bec767a49d017f0e46c69"), "name" : "Julius", "books" : [ DBRef("books", ObjectId("5b0bec767a49d017f0e46c64")), DBRef("books", ObjectId("5b0bec767a49d017f0e46c68")), DBRef("books", ObjectId("5b0bec767a49d017f0e46c67")), DBRef("books", ObjectId("5b0bec767a49d017f0e46c63")), DBRef("books", ObjectId("5b0bec767a49d017f0e46c65")), DBRef("books", ObjectId("5b0bec767a49d017f0e46c66")) ], "_class" : "com.test.springbootwithmongodb.entity.Author" } MongoTemplate 可以自己注入MongoTemplate来实现更多操作, 比如 private final MongoTemplate mongoTemplate; List<Customer> list = mongoTemplate.findAll(Customer.class); 索引 还可以这样设置联合索引 @Document @CompoundIndexes({ @CompoundIndex(name = "email_age", def = "{'email.id' : 1, 'age': 1}") }) public class User { // } 查询索引 db.user.getIndexes(); { "v" : 1, "key" : { "email.id" : 1, "age" : 1 }, "name" : "email_age", "ns" : "test.user" } 关注我的公众号 唯有不断学习方能改变! -- Ryan Miao

优秀的个人博客,低调大师

SpringMVC集成UEditor

UEditor是由百度开发的富文本web编辑器。其后端jsp代码实现的文件保存/读取路径受限于传统文件系统且只能在应用的webapp目录下, 故作出修改。但是暂没有使用官方后端代码,且只实现了图片上传下载功能。 1. 下载 下载地址:http://ueditor.baidu.com/website/download.html, 下载其中的jsp版本 文件解压后目录结构如下所示 目录结构.png 2. 搭建项目 2.1. 新建一个maven项目 2.2. pom依赖 <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> <junit.version>4.11</junit.version> <spring.version>4.3.9.RELEASE</spring.version> <fileupload.version>1.3.2</fileupload.version> <commons.io.version>2.3</commons.io.version> <slf4j.version>1.6.4</slf4j.version> <jackson.version>2.8.7</jackson.version> <fastjson.version>1.2.4</fastjson.version> <servlet.api.version>3.0.1</servlet.api.version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>${jackson.version}</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>${commons.io.version}</version> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>${fileupload.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${fastjson.version}</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>${servlet.api.version}</version> </dependency> </dependencies> 2.3. spring-mvc.xml <?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:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <mvc:annotation-driven/> <context:component-scan base-package="com.github.brandonbai.springmvcueditordemo.controller" /> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="defaultEncoding" value="utf-8" /> <property name="maxUploadSize" value="10485760000" /> <property name="maxInMemorySize" value="40960" /> </bean> <mvc:default-servlet-handler /> </beans> 2.4. applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"> <context:component-scan base-package="com.github.brandonbai.springmvcueditordemo" /> </beans> 2.5. 将ueditor下载解压后目录下图目录结构.png第1部分的代码拷贝到项目的webapp下,如下图所示: 项目结构.jpg 2.6. 将ueditor下载解压后目录下图目录结构.png第2部分config.json的代码拷贝到项目的src/main/resources下,如下图所示: config.png 3. 前端配置 修改2.4图中的ueditor.config.js的服务器请求路径 32 // 服务器统一请求接口路径 33 , serverUrl: URL + "./ueConvert" 4. 后端实现 UEditorController.java package com.github.brandonbai.springmvcueditordemo.controller; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.multipart.MultipartFile; import com.alibaba.fastjson.JSON; /** * * @author brandonbai * */ @Controller public class UEditorController { private static final String DIR_NAME = "~/Desktop"; private static final String PREFIX = "/editor/image"; private static final String FILE_SEPARATOR = File.separator; private static final String PATH_SEPARATOR = "/"; private static final String PATH_FORMAT = "yyyyMMddHHmmss"; private static final String CONFIG_FILE_NAME = "config.json"; private static final String ACTION_NAME_CONFIG = "config"; private static final String ACTION_NAME_UPLOAD_IMAGE = "uploadimage"; private static final Logger logger = LoggerFactory.getLogger(UEditorController.class); /** * 配置、图片处理 */ @RequestMapping("/ueConvert") public void ueditorConvert(HttpServletRequest request, HttpServletResponse response, String action, MultipartFile upfile) { try { request.setCharacterEncoding("utf-8"); response.setHeader("Content-Type", "text/html"); PrintWriter pw = response.getWriter(); if (ACTION_NAME_CONFIG.equals(action)) { String content = readFile(this.getClass().getResource(PATH_SEPARATOR).getPath() + CONFIG_FILE_NAME); pw.write(content); } else if (ACTION_NAME_UPLOAD_IMAGE.equals(action)) { Map<String, Object> map = new HashMap<String, Object>(16); String time = new SimpleDateFormat(PATH_FORMAT).format(new Date()); try { String originalFilename = upfile.getOriginalFilename(); String type = originalFilename.substring(originalFilename.lastIndexOf(".")); String dirName = DIR_NAME + PREFIX + FILE_SEPARATOR + time; File dir = new File(dirName); if(!dir.exists() || !dir.isDirectory()) { dir.mkdirs(); } String fileName = dirName + FILE_SEPARATOR + originalFilename; upfile.transferTo(new File(fileName)); map.put("state", "SUCCESS"); map.put("original", originalFilename); map.put("size", upfile.getSize()); map.put("title", fileName); map.put("type", type); map.put("url", "." + PREFIX + PATH_SEPARATOR + time + PATH_SEPARATOR + originalFilename); } catch (Exception e) { e.printStackTrace(); logger.error("upload file error", e); map.put("state", "error"); } response.setHeader("Content-Type", "application/json"); pw.write(JSON.toJSONString(map)); pw.close(); } } catch (Exception e) { e.printStackTrace(); } } /** * 图片读取 */ @RequestMapping(PREFIX + "/{time}/{path}.{type}") public void ueditorConvert(@PathVariable("time") String time, @PathVariable("path") String path, @PathVariable("type") String type, HttpServletRequest request, HttpServletResponse response) { try (FileInputStream fis = new FileInputStream(DIR_NAME + PREFIX + PATH_SEPARATOR + time + PATH_SEPARATOR + path + "." + type)) { int len = fis.available(); byte[] data = new byte[len]; fis.read(data); fis.close(); ServletOutputStream out = response.getOutputStream(); out.write(data); out.close(); } catch (Exception e) { logger.error("read file error", e); } } private String readFile(String path) { StringBuilder builder = new StringBuilder(); try(BufferedReader bfReader = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF-8"))) { String tmpContent = null; while ((tmpContent = bfReader.readLine()) != null) { builder.append(tmpContent); } bfReader.close(); } catch (Exception e) { e.printStackTrace(); } return builder.toString().replaceAll("/\\*[\\s\\S]*?\\*/", ""); } } 5.演示 demo.gif 示例代码 https://github.com/brandonbai/springmvc-ueditor-demo

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册