小编Ale*_*Tbk的帖子

Spring boot + thymeleaf:登录用户

我想知道,我如何从Thymeleaf获取User对象.目前我正在调用我的userService,它将从DB获取用户.我不喜欢这种方法,因为每次调用都会进行数据库查询.

是否有可能从内存中获取用户?

<link href="/css/style2.css"
    th:if="${@commanderService.getCurrentCommander()} and
        ${@commanderService.getCurrentCommander().settings == 'template=1'}" 
    rel="stylesheet" type="text/css" />
Run Code Online (Sandbox Code Playgroud)

CommanderService:

public Commander getCurrentCommander() {
    Object principal = 
        SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    Commander commander = findByName((String)principal);

    return commander;
}
Run Code Online (Sandbox Code Playgroud)

authentication spring spring-security thymeleaf spring-boot

6
推荐指数
1
解决办法
1万
查看次数

Cassandra:NoSpamLogger日志达到的最大内存使用量

每15分钟我看到这个日志条目:

2018-07-30 10:29:57,529 INFO [pool-1-thread-2] NoSpamLogger.java:91 log达到的最大内存使用量(512.000MiB),不能分配1.000MiB的块

我一直在阅读这个问题,但我看不出我的表格有什么问题: NoSpamLogger.java最大内存使用量已达到Cassandra

我有4张大桌子:

iot_data/derived_device_data histograms
Percentile  SSTables     Write Latency      Read Latency    Partition Size        Cell Count
                          (micros)          (micros)           (bytes)
50%             0.00              0.00              0.00               642                12
75%             0.00              0.00              0.00             17084               642
95%             0.00              0.00              0.00            263210             11864
98%             0.00              0.00              0.00           1629722             61214
99%             0.00              0.00              0.00           1955666             88148
Min             0.00              0.00              0.00               150                 0
Max             0.00              0.00              0.00           4055269            152321


iot_data/derived_device_data_by_year histograms
Percentile  SSTables     Write Latency      Read Latency    Partition Size        Cell Count
                          (micros) …
Run Code Online (Sandbox Code Playgroud)

cassandra elassandra

6
推荐指数
1
解决办法
1341
查看次数

UUID 或 Integer 是作为分区键的好选择吗?

两个简单的问题:

  • UUID 作为分区键是一个不错的选择吗?这会在集群中的所有节点之间平均分配数据吗?
  • (唯一的)整数是一个不错的选择吗?

这些选项中的任何一个都会创建“热”分区吗?

谢谢!

data-modeling cql cassandra

5
推荐指数
1
解决办法
1609
查看次数

Kubernetes 上的 NGINX 负载均衡

我有一些服务在 Kubernetes 中运行。我需要在它们前面放置一个 NGINX,根据 URL 重定向流量、处理 SSL 加密和负载平衡。

\n\n

有一个适用于该场景的有效 nginx.conf。我\xc2\xb4m缺少的是在gcloud上设置架构的正确方法。

\n\n

使用 nginx 启动 StatefulSet 并让负载均衡服务公开 NGINX 是否正确?我的理解是否正确,gcloud LB 会将配置的端口(fe 80 + 443)传递到我的 NGINX 服务,我可以在其中处理其余部分并将流量转发到后端服务?

\n

nginx google-cloud-platform kubernetes

5
推荐指数
1
解决办法
753
查看次数

Intellij 无法识别错误的返回类型

我有这个方法:

public <T extends CacheResult> T get(Object key, CacheDefinition cacheDefinition) {
    return load(key, cacheDefinition.name(), cacheDefinition.getTypeReference());
}
Run Code Online (Sandbox Code Playgroud)

现在我的 IDE 抱怨这一行(正如预期的那样,这是正确的),因为返回类型应该是CacheResult

User user = spxCacheManager.get(username, CacheDefinition.USERS_BY_USERNAME);
Run Code Online (Sandbox Code Playgroud)

我目前不明白的是,IDE(IntelliJ)并没有抱怨这一点:

List<User> usersFromCache = spxCacheManager.get(username, CacheDefinition.USERS_BY_USERNAME);
Run Code Online (Sandbox Code Playgroud)

这实际上是错误的。我在这里缺少什么?

java intellij-idea

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

Spring Boot:Thymeleaf 打包后不解析片段

我使用这样的片段:

@RequestMapping(value="/fragment/nodeListWithStatus", method= RequestMethod.GET)
public String nodeListWithStatus(Model model) {

    // status der nodes
    model.addAttribute("nodeList", nodeService.getNodeListWithOnlineStatus());

    return "/fragments :: nodeList";
}
Run Code Online (Sandbox Code Playgroud)

模板位于 /src/main/resources/templates 中。从 IntelliJ 启动应用程序时,这工作正常。一旦我创建了一个 .jar 并启动它,上面的代码就不再起作用了。错误:

[2014-10-21 20:37:09.191] log4j - 7941 ERROR [http-nio-666-exec-2] --- TemplateEngine: [THYMELEAF][http-nio-666-exec-2] Exception processing template "/fragments": Error resolving template "/fragments", template might not exist or might not be accessible by any of the configured Template Resolvers
Run Code Online (Sandbox Code Playgroud)

当我用 winrar 打开 .jar 时,我看到 /templates/fragments.html - 所以它似乎在那里。

我的 pom.xml 有这部分用于构建 jar(Maven 清理,安装):

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration> …
Run Code Online (Sandbox Code Playgroud)

spring fragment thymeleaf spring-boot

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

如何启动两个春季启动应用程序

我正在玩春季靴子.所以我想创建两个互相交互的微服务.我的问题是我无法启动它们,因为当第一个应用程序已经使用自己的tomcat运行时,第二个应用程序无法启动:

Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

谢谢!

spring tomcat spring-boot

0
推荐指数
2
解决办法
1393
查看次数