我正在使用一个简单的spring boot应用程序,该应用程序应该连接到PostgreSQL数据库并通过发送和接收JSON请求和响应来提供服务器功能。这是一个maven项目。
这些是我的pom.xml依赖项
TIMESTAMP
这是我目前正在使用的唯一控制器。
VARCHAR
这是User的实现
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.1</version>
<scope>test</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.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
</dependency>
<!-- JSTL for JSP -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>
</dependencies>
这是服务器的主要类别
package com.server.controller;
import com.server.entity.User;
import com.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
public class UserController {
@Autowired
UserService userService;
@RequestMapping(value = "/users/{id}", method = RequestMethod.GET)
public ResponseEntity<User> getUserById(@PathVariable Long id) {
return new ResponseEntity<User>(userService.findById(id),HttpStatus.OK);
}
@Autowired
@RequestMapping(value = "/users", method = RequestMethod.GET)
public ResponseEntity<List<User>> getUsers() {
return new ResponseEntity<List<User>>(userService.getAll(),HttpStatus.OK);
}
@Autowired
@RequestMapping(value = "/users", method = RequestMethod.POST)
public ResponseEntity<String> createAccount(@RequestBody User user) {
userService.create(user);
return new ResponseEntity<String>("Successful!", HttpStatus.CREATED);
}
}
我已经查看了与该异常相关的所有其他问题,但这些问题似乎都不起作用。我尝试过的事情是删除并添加某些依赖项,以及更改 package com.server.entity;
import javax.persistence.*;
@Entity
@Table(name = "login")
public class User {
@Id
@Column(name = "userID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
long id;
@Column(name = "username")
String username;
@Column(name = "password")
String password;
public User() {
super();
}
/**
* User constructor.
* @param username Receives a username String.
* @param password Receives a password String.
*/
public User(String username, String password) {
super();
this.username = username;
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public long getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
中的 package com.server;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@EnableAutoConfiguration(exclude = {JndiConnectionFactoryAutoConfiguration.class,DataSourceAutoConfiguration.class,
HibernateJpaAutoConfiguration.class, JpaRepositoriesAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class})
@SpringBootApplication
@ComponentScan("com.server.service.UserService")
@EnableJpaRepositories("com.server.repository.UserRepository")
class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
}
行。
完整的异常消息是
exclude
我对Spring Boot还是很陌生,因此缺少明显的东西也不是不可能的。 非常感谢帮助