package com.loginregister.loginregister.entities;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
@Entity
public class Role {
@Id
private String name;
@ManyToMany(mappedBy = "roles")
private List<User> users;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<User> getUsers() {
return users;
}
public void setUsers(List<User> users) {
this.users = users;
}
public Role(String name, List<User> users) {
this.name = name;
this.users = users;
}
public Role() {
}
public Role(String name) {
this.name = name;
}
}
角色JAVA
package com.loginregister.loginregister.entities;
import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import javax.persistence.GeneratedValue;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
@Entity
public class Task {
@Id
@GeneratedValue
private Long id;
@NotEmpty
private String date;
@NotEmpty
private String startTime;
@NotEmpty
private String stopTime;
@NotEmpty
private String Description;
@ManyToOne
@JoinColumn(name = "USER_EMAIL")
private User user;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getStopTime() {
return stopTime;
}
public void setStopTime(String stopTime) {
this.stopTime = stopTime;
}
public String getDescription() {
return Description;
}
public void setDescription(String description) {
Description = description;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Task(String date, String startTime, String stopTime, String description, User user) {
this.date = date;
this.startTime = startTime;
this.stopTime = stopTime;
Description = description;
this.user = user;
}
public Task(String date, String startTime, String stopTime, String description) {
this.date = date;
this.startTime = startTime;
this.stopTime = stopTime;
Description = description;
}
public Task() {
}
}
任务JAVA
package com.loginregister.loginregister.entities;
import org.springframework.scheduling.config.Task;
import javax.persistence.*;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Size;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import java.util.List;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
@Entity
public class User {
@Id
@Email
@NotEmpty
@Column(unique = true)
private String email;
@NotEmpty
private String name;
@Size(min = 4)
private String password;
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
private List<Task> tasks;
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "USER_ROLES",joinColumns = {
@JoinColumn(name = "USER_EMAIL", referencedColumnName = "email")
},inverseJoinColumns = {@JoinColumn(name = "ROLE_NAME", referencedColumnName = "name")})
private List<Role> roles;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public List<Task> getTasks() {
return tasks;
}
public void setTasks(List<Task> tasks) {
this.tasks = tasks;
}
public List<Role> getRoles() {
return roles;
}
public void setRoles(List<Role> roles) {
this.roles = roles;
}
public User(String email, String name, String password) {
this.email = email;
this.name = name;
this.password = password;
}
public User() {
}
}
使用者JAVA
package com.loginregister.loginregister.repositories;
import com.loginregister.loginregister.entities.Role;
import org.springframework.data.jpa.repository.JpaRepository;
public interface RoleRepository extends JpaRepository<Role, String>{
}
RoleRepository.java
package com.loginregister.loginregister.repositories;
import com.loginregister.loginregister.entities.Task;
import org.springframework.data.jpa.repository.JpaRepository;
public interface TaskRepository extends JpaRepository<Task, Long> {
}
TaskRepository。JAVA
package com.loginregister.loginregister.repositories;
import com.loginregister.loginregister.entities.User;
import org.springframework.data.jpa.repository.JpaRepository;
public interface UserRepository extends JpaRepository<User, String> {
}
用户库
package com.loginregister.loginregister;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class LoginRegisterApplication {
public static void main(String[] args) {
SpringApplication.run(LoginRegisterApplication.class, args);
}
}
登录注册应用程序。JAVA
spring.datasource.url=jdbc:mysql://localhost:3306/SpringAuth?useSSL=false
spring.datasource.username=root
spring.datasource.password=****
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create-drop
application.properties
http://maven.apache.org/xsd/maven-4.0.0.xsd"
<groupId>com.LoginRegister</groupId>
<artifactId>login-register</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>login-register</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.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-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<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-devtools</artifactId>
<scope>runtime</scope>
</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.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.0.7.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
波姆。xml
[错误]测试运行:1,失败:0,错误:1,跳过:0,耗时:2.941秒
这可以通过以下方式解决:
HibernateJPA2.1JAR是SpringBoot启动数据jpa的一部分。删除中的依赖项。m2文件夹,然后再次报告pom。xml
OR
我从以下链接下载了示例代码:https://spring.io/guides/gs/accessing-data-mysql/我更改了应用程序。属性文件如下: 之后,我转到源文件夹并运行以下命令:mvn clean spring boot:run发生此错误: 请帮我解决这个问题
尝试启动Spring Boot应用程序时,我收到以下错误: 注意:仅当我将自动连线注释置于IDeviceRepository IDeviceRepository上方时,才会发生此错误 。java类 我还没有让持久化到数据库-但是正在创建实体 这是项目的目录结构: com。美国广播公司。初始化。应用JAVA com.abc.controller.ontroller.java com。美国广播公司。服
我正在Spring中开发一个应用程序,使用Tomcat、Mysql5、Java8。。。问题是,由于“required bean‘entityManagerFactory’not found”问题,我无法部署它。我与同事一起开发了这个项目,但他们可以完美地部署它,即使我在Spring工具套件中复制粘贴相同的项目。怎么可能呢?错误: 这是我的pom.xml 这是我的存储库 这是我的控制器 应用属性 实
尝试运行我的Spring启动应用程序,我的编译器说;“_worldcom.example.hello字段回购。UserService需要一个名为entityManagerFactory的bean,但找不到。 注入点有以下注释:-@org.springframework.beans.factory.annotation.自动生成(必需=true)" Spring启动的新手,所以我不太确定为什么我的项
我只是在学习如何通过spring上传文档。所以,在进行这项工作时,我面临着上述问题。由于有许多问题与同一个问题相关,我参考了它们并尝试了所有方法,但没有一个问题得到纠正。事先,我不需要为我的存储库接口添加@Repository,也不需要在我的应用程序类中添加@EnableJpaRepositories,因为我已经使用了正确的包序列。如需更多参考,请参阅https://dzone.com/artic
感谢您的帮助! 我有一个spring boot应用程序要连接到couchbase,详细信息如下 > 存储库接口 控制器类 Couchbase配置 当我尝试启动应用程序时,它会抛出以下错误,我尝试在这里和外面搜索许多文章,但它们没有帮助 任何帮助都将不胜感激,否则情况似乎很好。