SpringBoot+Mysql+Ngnix+Docker事項

1、centos安裝docker

yum list docker //查看是否有docker安裝包
yum install docker

2、安裝docker-compose

#下載
sudo curl -L https://github.com/docker/compose/releases/download/1.20.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
#安裝
chmod +x /usr/local/bin/docker-compose
#查看版本
docker-compose version

3、

 下載一個demo項目,

導入項目

//pom.xml裏添加
<dependency>
	     <groupId>org.springframework.boot</groupId>
	     <artifactId>spring-boot-starter-web</artifactId>
</dependency>

//類新建一個VistorController
@RestController
public class VisitorController {

	@Autowired
    private VisitorRepository repository;
	
    @RequestMapping("/")
    public String index(HttpServletRequest request) {
        String ip=request.getRemoteAddr();
        Visitor visitor=repository.findByIp(ip);
        if(visitor==null){
            visitor=new Visitor();
            visitor.setIp(ip);
            visitor.setTimes(1);
        }else {
            visitor.setTimes(visitor.getTimes()+1);
        }
        repository.save(visitor);
        return "I have been seen ip "+visitor.getIp()+" "+visitor.getTimes()+" times.";
    }
}

再pom.xml添加這句代碼,然後再Appliction的子包或是同級目錄加入這個控制器

//pom.xml添加
<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</artifactId>
		</dependency>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
		</dependency>



//application.properties 添加配置
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.jpa.properties.hibernate.hbm2ddl.auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.show-sql=true

Linux快捷鍵

cd .. //返回上一級目錄
rm -f file //刪除文件
mv dir1 dir2 //重命名或移動
systemctl start docker.service //啓動一個服務
ps -ef | grep docker //查看進程
yum -y remove docker //卸載yum安裝的
wegt http:  //下載文件

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章