Spring boot在不同的机器上与Postgresql交互
我是Spring boot新手。我想集成我的流来读取或插入postgressql中的数据,我使用了crud存储库,但保存操作不会在托管在不同机器上的postgresql上保存任何内容。FindAll和find命令也会提供通过保存操作添加的数据,但不会提供我在数据库中添加的数据 应用程序属性Spring boot在不同的机器上与Postgresql交互,spring,spring-boot,postgresql-9.3,Spring,Spring Boot,Postgresql 9.3,我是Spring boot新手。我想集成我的流来读取或插入postgressql中的数据,我使用了crud存储库,但保存操作不会在托管在不同机器上的postgresql上保存任何内容。FindAll和find命令也会提供通过保存操作添加的数据,但不会提供我在数据库中添加的数据 应用程序属性 spring.datasource.url= jdbc:postgresql://160.110.67.94:5432/postgres spring.datasource.username=postgre
spring.datasource.url= jdbc:postgresql://160.110.67.94:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.jpa.generate-ddl=true
控制器
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.experian.model.RiskScoreBusinessRules;
import com.experian.repo.RiskScoreBusinessRulesRepository;
@RestController
public class WebController {
@Autowired
RiskScoreBusinessRulesRepository repository;
@RequestMapping("/save")
public String process(){
repository.save(new RiskScoreBusinessRules("Inherent Risks","Client`s business based risks", "Demographic","Client Location","Border crossings (airports, ports, marinas, Land border-crossings",120,"<89","89 to 178", ">178", "BR "));
//repository.save(new RiskScoreBusinessRules("Adam", "Johnson"));
// repository.save(new RiskScoreBusinessRules("Kim", "Smith"));
// repository.save(new RiskScoreBusinessRules("David", "Williams"));
// repository.save(new RiskScoreBusinessRules("Peter", "Davis"));
return "Done";
}
// public static final String customer_uri = "riskScore";
@RequestMapping("/findall")
public String findAll(){
String result = "<html>";
for(RiskScoreBusinessRules riskBR : repository.findAll()){
result += "<div>" + riskBR.toString() + "</div>";
}
return result + "</html>";
}
@RequestMapping("/findbyGroupName")
public String fetchDataByGroupName(@RequestParam("groupName") String groupName){
String result = "<html>";
for(RiskScoreBusinessRules riskBR: repository.findByGroupName(groupName)){
result += "<div>" + riskBR.toString() + "</div>";
}
return result + "</html>";
}
}
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.experian</groupId>
<artifactId>api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>experianAPI</name>
<description>Demo project for Experian</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
4.0.0
益百利
应用程序编程接口
0.0.1-快照
罐子
experianAPI
益百利演示项目
org.springframework.boot
spring启动程序父级
1.5.2.1发布
UTF-8
UTF-8
1.8
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
spring引导启动器数据jpa
org.postgresql
postgresql
运行时
org.springframework.boot
弹簧起动试验
测试
org.springframework.boot
springbootmaven插件
发布一些代码。否则很难判断问题出在哪里。请查找添加到问题中的更新代码
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.experian</groupId>
<artifactId>api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>experianAPI</name>
<description>Demo project for Experian</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>