一 概述
本次的项目是一个广告的上刊下刊等功能的项目。所使用的基础架构为springboot整合jpa等+mysql8.0。
二、注意事项
1.mysql驱动路径以及url需要添加时区
众所周知的,mysql的驱动路径变了,并且所访问的数据库还要加上时区了。如下所示:
spring.datasource.url=jdbc:mysql://localhost:3306/meixuan?useunicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
2.指定所生成的表的存储引擎为innodb
在resource文件夹中创建hibernate.properties文件,并写上
hibernate.dialect.storage_engine=innodb
3.使用@Autowired注解自动注入xxxService,然而为空
可能是xxxServiceImpl.java中忘记加@Service注解
通常在忘记@Service注解之后还会引起
Description:
Field employeeService in com.meixuan.Controller.OtherRolesController required a bean of type 'com.meixuan.Service.EmployeeService' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.meixuan.Service.EmployeeService' in your configuration.
发生这种情况可能是@Service忘记写了,也有可能是服务真的没有被扫描到,后者搜索解决。
4.将springboot项目部署到云端windows服务器中
4.1连接云端服务器远程桌面
https://jingyan.baidu.com/article/84b4f5655a944960f6da32bf.html 本次所使用的的服务器,上传文件,在本地复制,在远程桌面中粘贴即可
4.2使用jar方式部署到服务器中
https://blog.csdn.net/weixin_43760399/article/details/102588787
在上述引用的博客中,修改pom.xml中
<packaging>jar</packaging>
添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
是必须要修改的。其他的部分我并未做修改。本次我的项目的pom.xml内容为
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.meixuan</groupId>
<artifactId>AdvertisementMonitorForMeiXuan2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>AdvertisementMonitorForMeiXuan2</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.12</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
最后访问该项目只需要使用ip:8080/controller方式即可