我有两张桌子:TaStock和TaStockPrice.TaStockPrice表中的现场tastockid是表TaStock的外键.
@Entity
public class TaStock {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Integer id
@OneToMany(mappedBy = "taStock", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<TaStockPrice> tastockpriceList;
public void addTaStockPrice(TaStockPrice taStockPrice) {
if (taStockPrice == null) {
return;
}
taStockPrice.setTaStock(this);
if (tastockpriceList == null) {
tastockpriceList = new ArrayList<TaStockPrice>();
tastockpriceList.add(taStockPrice);
} else if (!tastockpriceList.contains(taStockPrice)) {
tastockpriceList.add(taStockPrice);
}
}
....
}
@Entity
public class TaStockPrice {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Integer id
@Column
private Integer tastockid;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "tastockid", nullable = …
Run Code Online (Sandbox Code Playgroud) 我在 Tomcat 7 上部署了一个应用程序,今天早上我注意到 Tomcat 控制台上有两条消息:
有人设法远程写入这些消息。我需要担心吗?有人黑了我的网站吗?
谢谢,
坦率
我有一个非常简单的 Web 应用程序,用于测试 @Scheduled 注释。方法读()RetrievePrices 类中的使用 @Scheduled 进行注释。在Tomcat上部署war后,我原以为read方法应该每5秒执行一次,但是Tomcat控制台什么也没显示。
主要的 SpringBoot 类
package com.aaaa.main;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
public class BatchMain {
public static void main(String[] args) {
SpringApplication.run(BatchMain.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
带有@Scheduled 注释的方法的类
package com.aaaa.schedule;
import org.springframework.scheduling.annotation.Scheduled;
public class RetrievePrices {
@Scheduled(fixedRate = 5000)
public void read() {
System.out.println(" ************* Scheduled(fixedRate = 5000) ");
}
Run Code Online (Sandbox Code Playgroud)
一个非常简单的Spring配置类
package com.aaaa.config;
@Configuration
@ComponentScan("com.aaaa")
@EnableScheduling
public class MyConfiguration {
}
Run Code Online (Sandbox Code Playgroud)
聚甲醛
<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> …
Run Code Online (Sandbox Code Playgroud) 我正在使用 spring boot,我想将 logback.xml 文件放在类路径之外,以便我可以更轻松地更改 logback.xml 的内容。我使用的是 Windows 10,logback.xml 文件的位置是:
C:\apache-tomcat-9.0.37-50099
我确实在 application.yaml 中指定了这个位置,如下所示
logging:
config: "C:/apache-tomcat-9.0.37-50099/logback.xml"
Run Code Online (Sandbox Code Playgroud)
但是spring找不到logback.xml的位置,因为没有创建日志文件。如何指定 logback.xml 文件的位置?
我在 SpringBoot 项目中使用 OpenApi 3 来生成 Swagger html 页面。
POM.xml 中的依赖项:
Run Code Online (Sandbox Code Playgroud)<dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-ui</artifactId> <version>1.5.12</version> </dependency>
在控制器类中,我在方法上方定义了以下注释。
@Operation(
summary = "Get a list of letters for a specific user",
description = "Get a list of letters for a specific user",
tags = {"letters"}
)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "success", content = {@Content(
mediaType = "application/json",
array = @ArraySchema(schema = @Schema(implementation = LetterDTO.class)))}),
@ApiResponse(responseCode = "400", description = "BAD REQUEST"),
@ApiResponse(responseCode = "401", description = "UNAUTHORIZED"),
@ApiResponse(responseCode …
Run Code Online (Sandbox Code Playgroud) 我正在使用 SpringBoot 并具有以下依赖项
Run Code Online (Sandbox Code Playgroud)<dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-ui</artifactId> <version>1.5.12</version> </dependency>
控制器类(@RestController)有一个入口点(@GetMapping),该入口点应返回对象的列表:MyClass.java。我在方法上方添加了 Swagger 注释,以便通过 swagger UI 页面创建 API 文档。
swagger文档应该表明返回对象的类型
列表<我的班级>
但我该怎么做呢?如果我做
“@Schema(实现 = List<MyClass>.class)”
出现编译错误。
招摇注解:
Run Code Online (Sandbox Code Playgroud)@Operation(....) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "successful operation", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ????)) }), @ApiResponse(...), @ApiResponse(...) @GetMapping(value = "/aaa", produces = MediaType.APPLICATION_JSON_VALUE) public List<MyClass> getAaa(...) { return ... }
我正在尝试设置一个基本的JPA插入测试.但是DB中没有保存任何东西.DB是Postgresql.Hibernate用作持久性提供程序.
提前谢谢了.
@Entity
public class Currency {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Integer id;
@Column
private String code;
@Column
private String name;
...
}
Run Code Online (Sandbox Code Playgroud)
CRUD类:
@Repository
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@Transactional(propagation = Propagation.REQUIRED)
public class CRUDServiceBean implements CRUDService {
@PersistenceContext(type = PersistenceContextType.EXTENDED)
private EntityManager entityManager;
public EntityManager getEntityManager() {
return entityManager;
}
public <T extends BaseEntity> T persistAndCommit(T t) {
entityManager.persist(t);
entityManager.refresh(t);
entityManager.getTransaction().commit();
return t;
}
...
...
}
Run Code Online (Sandbox Code Playgroud)
所有测试的基类:
@RunWith(SpringJUnit4ClassRunner.class)
@Configurable(autowire = Autowire.BY_NAME)
@ContextConfiguration(locations = { "classpath:context-test.xml" })
public class BaseTest { …
Run Code Online (Sandbox Code Playgroud) 我有一个依赖于 springdoc-openapi 的 spring boot 应用程序(2.5.6)。但是,启动 swagger-ui (http://localhost:8080/v1/swagger-ui/index.html) 不起作用。调试日志表明index.html 不存在。找不到index.html 的原因可能是什么?
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.8</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
应用程序.yaml
springdoc:
swagger-ui:
tagsSorter: alpha
operations-sorter: alpha
doc-expansion: none
disable-swagger-default-url: true
logging:
level:
root: DEBUG
server:
port: 8080
spring:
application:
name: fe-applic-app
api-version: "v1"
Run Code Online (Sandbox Code Playgroud)