小编Ege*_*men的帖子

没有为Lombok getter和setter生成Javadoc

我遇到了为Lombok getter和setter生成Javadoc的问题.我在这里尝试了两个建议.示例字段及其文本如下:

/**  
 *  Identifier of the client
 * 
 *  @param clientID changes the id of the client 
 *  @return id of the client
 */
@Getter @Setter private Integer clientID;
Run Code Online (Sandbox Code Playgroud)

但是,我在生成的Javadoc中既没有看到getter也没有看到setter.我在Eclipse上使用'protected'可见性(Project - > Generate Javadoc ...).我的龙目岛版本是1.12.4.有什么建议?

javadoc lombok

25
推荐指数
1
解决办法
7801
查看次数

Spring Boot如何在请求过滤器中获取资源方法

我正在使用 Spring Boot 构建 REST API,现在尝试创建一个自定义过滤器类,我需要在其中访问请求将调用的资源方法。我需要它来检查该方法是否用某个注释进行注释,例如

@Component
@ApplicationScope
public class MyFilter extends OncePerRequestFilter {

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        Method method = // get the target method somehow
        if (method.isAnnotationPresent(MyAnnotation.class)) {
            // business logic here
        }
        filterChain.doFilter(request, response);
    }
}
Run Code Online (Sandbox Code Playgroud)

使用 RESTEasy 我会做这样的事情

@Context
private ResourceInfo resourceInfo;
Run Code Online (Sandbox Code Playgroud)

其中 ResourceInfo 具有获取作为请求目标的资源类和方法的方法。Spring Boot 中是否有类似的类可以完成相同的工作?

rest spring-boot

6
推荐指数
0
解决办法
1367
查看次数

运行测试时,Spring Boot“ PSQLException:致命:抱歉,已经有太多客户端”

我有一个Spring Boot应用程序,它为前端提供REST API。我正在使用jOOQ和Postgresql。我目前在本地执行所有集成测试时遇到此错误(大约1000个测试,这在执行700-800个测试后开始发生):

org.postgresql.util.PSQLException: FATAL: sorry, too many clients already
Run Code Online (Sandbox Code Playgroud)

我试图通过来限制最大空闲和活动连接application.properties,但似乎这些值有些被忽略了。我仅使用以下语句在执行测试时监视打开的连接:

SELECT datname, state, query FROM pg_stat_activity;
Run Code Online (Sandbox Code Playgroud)

这就是我的application.properties的样子:

spring.datasource.driverClassName = org.postgresql.Driver
spring.datasource.url = jdbc:postgresql://localhost:5432/xxx
spring.datasource.username = xxx
spring.datasource.password = xxx
spring.datasource.initialize = true
spring.datasource.continue-on-error = false
spring.jooq.sql-dialect = POSTGRES
spring.datasource.max-active = 50
spring.datasource.max-idle = 5
Run Code Online (Sandbox Code Playgroud)

这就是我创建数据源的方式:

@ConfigurationProperties(prefix = "spring.datasource")
@Bean
public DataSource dataSource() {
    return DataSourceBuilder
            .create()
            .build();
}
Run Code Online (Sandbox Code Playgroud)

我看到jOOQ使用正确的数据源,并且jOOQ正确处理了连接(从数据源获取和释放连接)。因此,问题不应该在jOOQ方面。

max_connections = 200postgresql.conf,所以我的Spring配置应该没问题。在运行测试时,我看到的空闲连接pg_stat_activity比配置中指定的要多得多。最终由于这些测试而导致测试开始失败时,PSQLException我在中看到大约90-100个空闲连接pg_stat_activity。因此,这产生了两个问题:

  1. 为什么我的本地数据库应该允许比我看到的更多的连接,但我的测试还是失败了pg_stat_activity
  2. 似乎我中的数据源配置application.properties …

postgresql datasource spring-boot

6
推荐指数
2
解决办法
1857
查看次数

如何在Flutter中链接文本

Flutter中是否有一种简单的方法可以“链接”包含纯文本,电子邮件和Web URL的文本?例如,如果我的文字是My phone number is 099 123 45 67 and my email is test@test.com电话号码,并且电子邮件将显示为可点击的链接。

在Android中,它将是一个衬里:

textView.setAutoLinkMask(Linkify.ALL);
Run Code Online (Sandbox Code Playgroud)

我已经看到在这里提出了类似的问题。该解决方案适用于静态文本,但对于动态文本,解析文本,检测所有URL,电话号码,电子邮件等,并使用TextSpans进行渲染会复杂得多。

dart flutter

4
推荐指数
4
解决办法
2053
查看次数

Flutter-选择项目后弹出菜单未关闭

我正在尝试Flutter,却遇到了问题PopupMenuButton。在菜单中选择一个项目后,我将显示一个没有菜单的新屏幕,并且在向后导航后,弹出菜单仍处于打开状态-如以下屏幕截图所示:

弹出菜单 编辑个人资料

从编辑个人资料屏幕(第二个屏幕截图)导航到帐户屏幕(第一个屏幕截图)后,弹出菜单仍然打开。我希望将其关闭。我在应用栏内创建弹出菜单的相关代码:

      actions: <Widget>[
    new PopupMenuButton(
      itemBuilder: (BuildContext context) {
        return <PopupMenuEntry>[
          new AppBarMenuItem("Edit profile", () => Navigator.pushNamed(context, Routes.editProfile)).build(context),
          new AppBarMenuItem("Option 1", () => {}).build(context),
          new AppBarMenuItem("Option 2", () => {}).build(context),
          new AppBarMenuItem("Option 3", () => {}).build(context),
          new AppBarMenuItem("Option 4", () => {}).build(context),
        ];
      },
    ),
  ],
Run Code Online (Sandbox Code Playgroud)

AppBarMenuItem

new PopupMenuItem(
  child: new InkWell(
    child: new Text(_label),
    onTap: _onTap,
)
Run Code Online (Sandbox Code Playgroud)

选择项目后如何确保弹出菜单关闭?看来,如果我只是PopupMenuItem在自己的菜单中使用PopupMenuButton并导航至新屏幕,onSelected则菜单会正确关闭。但是当我使用它的onTap功能时,InkWell它不再关闭。

flutter

3
推荐指数
2
解决办法
2651
查看次数

Spring Boot Rest - OffsetDateTime 以浮点形式返回

我有一个 Spring Boot 应用程序 (2.4.1),其中一个OffsetDateTime字段作为浮点值从RestController. 例子:

"created_at": 1616080724.531610100
Run Code Online (Sandbox Code Playgroud)

我尝试了该线程中所有建议的解决方案。他们都不为我工作。

我还尝试添加一个非常简单的端点,仅返回OffsetDateTime

@GetMapping("/test")
public OffsetDateTime test() {
    return OffsetDateTime.now();
}
Run Code Online (Sandbox Code Playgroud)

结果是相同的,它以浮点值形式返回。

然后我在一个最小的 Spring Boot 项目中尝试了相同的端点,它按预期以 ISO 格式返回:

"2021-03-18T15:39:14.5295632+01:00"
Run Code Online (Sandbox Code Playgroud)

这一切都表明某些传递依赖关系与 Sprint Boot 使用的默认 Jackson 序列化程序相混淆。但mvn dependency:tree没有给我任何可疑的依赖项(例如没有 gson marshaller 依赖项)。

我还尝试启用 TRACE 日志记录,我可以看到写入的对象HttpEntityMethodProcessor具有正确格式的created_at时间:

TRACE org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor - Writing [class MyObject {
....
createdAt: 2021-03-18T16:37:34.113316500+01:00
...
Run Code Online (Sandbox Code Playgroud)

但它最终仍然在客户端作为浮动(在浏览器和 Postman 上进行测试)。这里可能有什么问题?

rest serialization json jackson spring-boot

2
推荐指数
1
解决办法
1134
查看次数

Spring Boot + Thymeleaf css 不适用于模板

我正在评估 Thymeleaf 和 Flying Saucer 以从模板生成 pdf,我在将 css 应用到我的 Thymeleaf 模板时遇到了问题。我已经在这里这里这里阅读了相关的问题和答案;但没有一个建议的解决方案解决了我的问题。

这是我的资源文件夹的样子:

在此处输入图片说明

所以我使用的是 Spring 将寻找的默认目录。这就是我的 head 标签的样子template.html

<head>
    <title>Spring Boot and Thymeleaf Example</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <link rel="stylesheet" type="text/css" href="../static/css/style.css" th:href="@{/css/style.css}"/> 
</head>
Run Code Online (Sandbox Code Playgroud)

如果我内联我的 css,template.html那么生成的 pdf 文件的样式将正确(因此我生成 pdf 的方式应该没有问题)。但是,当我尝试链接到如上所示的 css 文件时,生成的 pdf 未设置样式(因此未应用 css)。

最后,我可以在 访问我的 css 文件http://localhost:8080/css/style.css,因此 Spring 提供静态内容似乎没有问题。

为了完整起见,这就是我生成 pdf 的方式:

private final SpringTemplateEngine templateEngine;
private final Log log;

@Autowired
public PdfGenerator(SpringTemplateEngine templateEngine) {
    this.templateEngine = …
Run Code Online (Sandbox Code Playgroud)

css thymeleaf spring-boot

0
推荐指数
1
解决办法
6593
查看次数