@GET http://localhost:8080/batchConfig/findConfigs
我的控制器
@RestController
@RequestMapping(path = "/batchConfig")
public class BatchJobConfigController {
@Autowired
private BatchJobConfigRepository repository;
/*
* Mapping url exmaple:http://localhost:8080/batchConfig/findConfigs
*/
@GetMapping(value = "/findConfigs", consumes = MediaType.ALL_VALUE)
List<BatchJobConfig> findAll() {
return repository.findAll();
}
/*
* http://localhost:8080/batchConfig/findConfigs?configId=1
*/
@GetMapping(value = "/findConfigs/{configId}", consumes = MediaType.ALL_VALUE)
BatchJobConfig findOneBatchJobConfig(@PathVariable Long id) {
return repository.findById(id).orElseThrow(() -> new BatchJobConfigNotFoundException(id));
}
}
主班
@SpringBootApplication
public class StartBatchJobConfigurationApplication {
Date date = new Date();
// start everything
public static void main(String[] args) {
SpringApplication.run(StartBatchJobConfigurationApplication.class, args);
}
// run this only on profile 'demo', avoid run this in test
@Profile("demo")
@Bean
CommandLineRunner initDatabase(BatchJobConfigRepository configRepository,
BatchJobConfigDetailsRepository detailsRepository) {
return args -> {
configRepository.save(new BatchJobConfig(1L, "JAVA"));
configRepository.save(new BatchJobConfig(2L, "CC"));
}
}
}
型号
@Entity
@Table(name = "BATCH_JOB_CONFIG")
public class BatchJobConfig2 {
// @OneToMany(mappedBy = "BATCH_JOB_CONFIG")
// private Set<BatchJobConfigDetails> batchJobConfigDetails;
@Id
private long batchJobConfigId;
private String addUserCd;
public BatchJobConfig2(long batchJobConfigId, String addUserCd) {
super();
this.batchJobConfigId = batchJobConfigId;
this.addUserCd = addUserCd;
}
public long getBatchJobConfigId() {
return batchJobConfigId;
}
public void setBatchJobConfigId(long batchJobConfigId) {
this.batchJobConfigId = batchJobConfigId;
}
public String getAddUserCd() {
return addUserCd;
}
public void setAddUserCd(String addUserCd) {
this.addUserCd = addUserCd;
}
}
存储库
@Repository
public interface BatchJobConfigRepository extends JpaRepository<BatchJobConfig, Long> {
}
application.properties
logging.level.org.springframework=INFO
logging.level.root=ERROR
server.error.include-stacktrace=never
spring.profiles.active=demo
#spring.main.banner-mode=off
# Automatically update the database
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driver-class-name=com.ibm.db2.jcc.DB2Driver
# The database connection URL
spring.datasource.url=jdbc:db2://tetet:50002/testt
# Username
spring.datasource.username=tyyy
# Password
spring.datasource.password=rrrrr
# Define the database platform
spring.jpa.database-platform=org.hibernate.dialect.DB2Dialect
# Define the naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
# Define the default schema
spring.jpa.properties.hibernate.default_schema=schema
log4j.properties
# Root logger option
log4j.rootLogger=INFO, file
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
#Redirect to Tomcat logs folder
#log4j.appender.file.File=${catalina.home}/logs/logging.log
log4j.appender.file.File=C:\\logigng.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.logger.org.hibernate.util.JDBCExceptionReporter=ERROR
log4j.logger.org.hibernate.engine.jdbc.spi.SqlExceptionHelper=ERROR
log4j.logger.org.hibernate=ERROR
错误的可能原因:
网络错误:主机不可访问 证书问题:指定了https,但是服务使用的是自签名证书,过期证书或其他有问题的证书 CORS错误:请求的服务不允许来自其他域的请求。请尝试在chrome中添加Swagger Inspector Extension,因为它可以解决此问题。 Swagger检查器扩展程序可能已禁用。请尝试通过以下网址启用它:chrome:// extensions。
答案 0 :(得分:1)
我通过关闭所有打开的命令行窗口而不是杀死用于该应用程序的端口来解决此问题。