分类目录归档:未分类

Docker之开启远程访问的实现(Eclipse打开远程资源区)

有这么个需求,我需要通过eclipse的 mvn package docker:build 的方式来进行部署docker容器的时候,我们是window的环境,这时候,就需要一个远程的docker来进行部署服务。

 

打开/usr/lib/systemd/system/docker.service文件,修改ExecStart这行。

 

vim /usr/lib/systemd/system/docker.service

ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

#重新加载配置文件
systemctl daemon-reload  

#重启服务
systemctl restart docker.service 

#查看端口是否开启
netstat -nptl

#直接curl看是否生效
curl http://127.0.0.1:2375/info

  

 

#查看端口是否开启
netstat -nptl

 

 

测试访问端口

 

 

 

 

 eclipse连接远程资源

填好URl后点击【Test-Connection】弹出如下界面

 

再点击【Finish】

 

 

即可完成。

 

Springboot集成swagger

1.引入jar包

		<!-- springfox-swagger -->
	    <dependency>
	        <groupId>io.springfox</groupId>
	        <artifactId>springfox-boot-starter</artifactId>
	        <version>3.0.0</version>
	    </dependency>

2.编写配置类

package com.qyc.Microservice.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.AbstractEnvironment;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


/**
 * 访问地址:
 *   /swagger-ui/index.html
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
	
    @Autowired
    private AbstractEnvironment env;
	
    @Bean
    public Docket createRestApi() {
    	//是否开启swagger,正式环境一般是需要关闭的(避免不必要的漏洞暴露!),可根据springboot的多环境配置进行设置
    	String swaggerflag = env.getProperty("swagger.enable");
    	
    	if("true".equals(swaggerflag)){
            return new Docket(DocumentationType.SWAGGER_2)
                    .pathMapping("/")
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("com.qyc.Microservice.controller"))
                    .paths(PathSelectors.any())
                    .build().apiInfo(new ApiInfoBuilder()
                            .title("项目接口接口说明")
                            .description("详细信息......")
                            .version("1.0")
                            .contact(new Contact("JoePotter","https://www.cnblogs.com/JoePotter/","252177507@qq.com"))
                            .license("The Apache License")
                            .licenseUrl("https://www.cnblogs.com/JoePotter/")
                            .build());
    	}else {
            return new Docket(DocumentationType.SWAGGER_2)
                    .pathMapping("/")
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("com.qyc.Microservice.controller"))
                    .paths(PathSelectors.any())
                    .build().apiInfo(new ApiInfoBuilder()
                            .title("项目接口接口说明")
                            .description("详细信息......")
                            .version("1.0")
                            .contact(new Contact("JoePotter","https://www.cnblogs.com/JoePotter/","252177507@qq.com"))
                            .license("The Apache License")
                            .licenseUrl("https://www.cnblogs.com/JoePotter/")
                            .build()).enable(false);
    	}
    }
}

3.对接口和实体类添加注释,生成doc。常用的标记如下

@Api()用于类;
标识这个类是swagger的资源
  tags–表示分组说明标签

@ApiOperation()用于方法;
表示一个http请求的操作
  value用于方法描述

  notes用于提示内容

@ApiModel()用于实体类
表示对类进行说明,用于参数用实体类接收

value–表示对象名
description–描述

@ApiModelProperty()用于实体类字段
表示对model属性的说明或者数据操作更改
  value–字段说明
  name–重写属性名字
  dataType–重写属性类型
  required–是否必填
  example–举例说明
  hidden–隐藏

@ApiImplicitParam() 用于 controller 方法
表示单独的请求参数
  name–参数ming
  value–参数说明
  dataType–数据类型
  paramType–参数类型
  example–举例说明

@ApiImplicitParams() 用于 controller 方法,包含多个 @ApiImplicitParam

@ApiIgnore()用于类或者方法上,可以不被swagger显示在页面上

说明:简单的标记只需要@Api(tags=””) 和 @ApiOperation(value=””,notes=””)

@RestController
@RequestMapping("/user")
@Api(tags = "用户登录")
public class LoginController extends BaseController {

	@Autowired
	private UserService userService;
	
	@PostMapping("/save")
	@ApiOperation(value = "新建用户!",notes = "提示信息。")
	public void save(@Valid User user) {
		userService.saveMapper( user);
	}

  

 

Xmind8默认打开文件在当前目录出现临时文件问题修改为红色文字部分

-configuration
@user.home/AppData/Roaming/XMind/configuration-cathy_win32
-data
@user.home/AppData/Roaming/XMind/workspace-cathy
-startup
plugins/org.eclipse.equinox.launcher_1.3.200.v20160318-1642.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.400.v20160518-1444
--launcher.defaultAction
openFile
-eclipse.keyring
@user.home/Application Data/XMind/secure_storage
-vmargs
-Dfile.encoding=UTF-8
-Xms128m
-Xmx1024m
-XX:MaxPermSize=256m

  

nginx centos 服务开机启动设置实例详解

这篇文章主要介绍了nginx centos 服务开机启动设置实例详解的相关资料,这里对服务开机启动做了详细的步骤介绍,需要的朋友可以参考下

 

nginx centos 服务开机启动设置

 

建立服务文件

以nginx 为例

vim /lib/systemd/system/nginx.service 

在nginx.service 中插入一下内容

 

[Unit] 
Description=nginx 
After=network.target 

[Service] 
Type=forking 
ExecStart= 服务启动命令
ExecReload= 服务重启命令
ExecStop=服务停止命令
PrivateTmp=true 

[Install] 
WantedBy=multi-user.target 

  

[Unit]:服务的说明
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径

以754的权限保存在目录:/lib/systemd/system 

设置开机自启动:

systemctl enable nginx.service

相关命令

功能                                       cnetos7以前                                          cnetos7
显示所有已启动的服务            chkconfig –list                 systemctl list-units –type=service

启动某服务       service nginx start systemctl             start nginx.service 或 systemctl start nginx

停止某服务       service nginx stop systemctl             stop nginx.service 或 systemctl stop nginx

重启某服务       service nginx restart                    systemctl restart nginx.service 或 systemctl restart nginx

使某服务自动启动     chkconfig –level 3 nginx  on       systemctl enable nginx.service 或 systemctl enable nginx

使某服务不自动启动     chkconfig –level 3 nginx off    systemctl disable nginx.service 或 systemctl disable nginx

检查服务状态       service nginx status                 systemctl is-active nginx.service (仅显示是否)Activesystemctl status nginx.service (服务详细信息)

 

Springboot集成Mybatis

MyBatis 是一款优秀的持久层框架,它支持定制化 SQL、存储过程以及高级映射。MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集。MyBatis 可以使用简单的 XML 或注解来配置和映射原生类型、接口和 Java 的 POJO(Plain Old Java Objects,普通老式 Java 对象)为数据库中的记录。

Mybatis架构

 

 

1. 添加maven 依赖

<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>

2.添加相关配置文件(数据库链接等相关配置)

 

一、无配置文件注解版

1.在启动类中添加对mapper包扫描@MapperScan(或者直接在Mapper类上面添加注解@Mapper,建议使用上面那种)

 

 2.开发Mapper

#{} 只是替换,相当于PreparedStatement使用占位符去替换参数,可以防止sql注入。 ${} 是进行字符串拼接,相当于sql语句中的Statement,使用字符串去拼接sql;$可以是sql中的任一部分传入到Statement中,不能防止sql注入。(比如说我们的入参是表名的时候,使用${})

    @Select 是查询类的注解,所有的查询均使用这个
    @Result 修饰返回的结果集,关联实体类属性和数据库字段一一对应,如果实体类属性和数据库属性名保持一致,就不需要这个属性来修饰。

    @Insert 插入数据库使用,直接传入实体类会自动解析属性到对应的值
    @Update 负责修改,也可以直接传入对象@delete 负责删除

 

package com.qyc.Microservice.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.qyc.Microservice.dto.User;

public interface UserMapper {

	@Insert("insert into user(age,name,password,sex) values (#{age},#{name},#{password},#{sex})")
	public void insert(User user);
	
	@Update("update user set name=#{name},age=#{age},password=#{password},sex=#{sex} where id=#{id}")
	public int update(User user);
	
	@Delete("delete from user where id=#{id}")
	public int delete(User user);
	
	@Select("select * from user where name = #{name} and password =#{password}")
	public User select(User user);
}

  

	@Test
	public void userSave() {
		User user = new User();
		user.setName("aa11a");
		user.setAge(20);
		user.setSex(0);
		user.setPassword("alsdja");
		
		userService.saveMapper(user);
	}

  

二、配置文件版

1 . pom文件和上个版本一样,只是application.properties新增以下配置
mybatis.config-locations=classpath:mybatis/mybatis-config.xml(可选)
mybatis.mapper-locations=classpath:mybatis/mapper/*.xml

 

linux中查看java进程

查看进程可以使用 

ps -ef|grep java

  

 

 

关闭某个进程 

比如:60355

 

 

  kill -9 60355

通过 ps -ef | grep java  得到如上线程将某线程终止时用 

kill -9 XXXXX     XXXXX为上述查出的序号  如: 19979线程终止为: kill -9 4834 

 

kill一个线程时需注意不要误停止了不应该停止的线程造成不必要的麻烦。 

在相当确信时才可用此方法停止线程。

mybatis关于jdbc连接报错,5.5.62MySQL连接,出现com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure等问题解决方法

首先mysql连接的驱动在5.7版本及之前驱动是

com.mysql.jdbc.Driver

在8.0更新之后需要注意,已经换成了以下的需要加cj

om.mysql.cj.jdbc.Driver

如果出现com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure等问题首先检查jdbc的url是否正确,在8.0以上需要注意,有些参数已经被废弃但是必须的参数有以下

jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncodeing=UTF-8&useSSL=false&serverTimezone=GMT

连接的符号也从“&”换成”&amp;“注意其他的符号在在xml文件中并不支持,有些参数已经被废弃,以上的都是在MySQL8.0版本出现的问题。

 

同时还需要检查驱动是否对应了版本号

参照地址:

https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-versions.html