小编ale*_*xbt的帖子

为什么左联接会导致优化器忽略索引?

使用postgres 9.6.11,我有一个类似的架构:

所有者:

id: BIGINT (PK)
dog_id: BIGINT NOT NULL (FK)
cat_id: BIGINT NULL (FK)

index DOG_ID_IDX (dog_id)
index CAT_ID_IDX (cat_id)
Run Code Online (Sandbox Code Playgroud)

动物:

id: BIGINT (PK)
name: VARCHAR(50) NOT NULL

index NAME_IDX (name)
Run Code Online (Sandbox Code Playgroud)

在某些示例数据中:

所有者表:

| id | dog_id | cat_id |
| -- | ------ | ------ |
| 1  | 100    | 200    |
| 2  | 101    | NULL   |
Run Code Online (Sandbox Code Playgroud)

动物桌:

| id  | name     |
| --- | -------- |
| 100 | "fluffy" |
| 101 …
Run Code Online (Sandbox Code Playgroud)

sql postgresql left-join database-performance full-table-scan

7
推荐指数
1
解决办法
90
查看次数

Spring MVC将jsp作为text/plain内容类型返回

我有Spring MVC和jsp网页的问题.

当我请求网页时,它默认返回text/plain.我尝试在控制器上手动将内容类型设置为text/htmlHttpServletResponse,并且Web浏览器重新协调它,正确显示它但是在主体上编码jsp标记.例:

JSP:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Error 405 ******* </title>
    </head>
    <body> asdasdsasad </body>
</html>
Run Code Online (Sandbox Code Playgroud)

浏览器收到:

<html>
   <body>&lt;%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%&gt;

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Title</title>

    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

我正在使用Spring Boot和基于java web的注释进行配置.另外,我正在使用@EnableAutoConfiguration,我发现通过将sevlet从"/*"映射到"/"来解决问题.

由于java注释,我不得不重写dispatchedServlet(https://github.com/spring-projects/spring-boot/issues/91#issuecomment-27626036),配置类是:

@Configuration
public class DispatcherConfiguration {

@Bean
public ServletRegistrationBean dispatcherRegistration() {
    ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet());
    registration.addUrlMappings("/");
    registration.setLoadOnStartup(1); …
Run Code Online (Sandbox Code Playgroud)

spring spring-mvc spring-boot

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

使用Spring Boot自定义Jetty的HttpConfiguration

我正在使用spring boot(截至目前为1.2.1),我需要增加默认的8k请求头大小限制,该限制存在HttpConfiguration于Jetty的类中.看看JettyEmbeddedServletContainerFactory哪些我可以掌握,EmbeddedServletContainerCustomizer但无法看到如何改变它的方式.

我也确实看了一下JettyServerCustomizer- 我明白我可以Server通过它再次抓住码头- 没办法怎么改变HttpConfiguration这里.

任何提示将不胜感激.

embedded-jetty spring-boot jetty-9

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

如何在Spring Boot和RabbitMQ中配置和receiveAndConvert jSON有效负载到域对象

最近,我对使用Spring Boot的微服务架构产生了浓厚的兴趣.我的实现有两个Spring启动应用程序;

应用的一个接收请求从一个RESTful API,转换并发送有效载荷JSON到的RabbitMQ queueA.

应用程序二,已订阅queueA,接收jSON有效负载(域对象用户),并且应该激活Application Two中的服务,例如.向用户发送电子邮件.

在我的Application Two配置中不使用XML ,如何配置将从RabbitMQ接收的jSON有效负载转换为域对象用户的转换器.

以下是Application Two上Spring Boot配置的摘录

Application.class

@SpringBootApplication
@EnableRabbit
public class ApplicationInitializer implements CommandLineRunner {

    final static String queueName = "user-registration";

    @Autowired
    RabbitTemplate rabbitTemplate;

    @Autowired
    AnnotationConfigApplicationContext context;

    @Bean
    Queue queue() {
        return new Queue(queueName, false);
    }

    @Bean
    TopicExchange topicExchange() {
        return new TopicExchange("user-registrations");
    }

    @Bean
    Binding binding(Queue queue, TopicExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(queueName);
    }

    @Bean
    SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {
        SimpleMessageListenerContainer container = new …
Run Code Online (Sandbox Code Playgroud)

java spring rabbitmq spring-amqp spring-boot

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

功能 - 切换Spring组件

我有一个Spring Boot应用程序,包含很多@ Component,@ Controller,@ RestartController注释组件.有大约20种不同的功能我想分开切换.重要的是,可以在不重建项目的情况下切换功能(重启就可以了).我认为Spring配置会很好.

我可以像这样对配置(yml)进行成像:

myApplication:
  features:
    feature1: true
    feature2: false
    featureX: ...
Run Code Online (Sandbox Code Playgroud)

主要问题是我不想在所有地方使用if-blocks.我宁愿完全禁用组件.例如,甚至应该加载@RestController,它不应该注册它的pathes.我正在寻找这样的东西:

@Component
@EnabledIf("myApplication.features.feature1")  // <- something like this
public class Feature1{
   // ...
}
Run Code Online (Sandbox Code Playgroud)

有这样的功能吗?有没有一种简单的方法可以自己实现它?或者是否有另一种功能切换的最佳实践?

顺便说一句:Spring Boot版本:1.3.4

java spring spring-boot featuretoggle

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

Eclipse中已终止的Spring Boot应用程序 - 未调用Shutdown挂钩

我有一个Spring Boot + Spring Data Redis/KeyValue项目.我设置了一个Spring配置文件来运行嵌入了所有依赖项的应用程序.所以在启动时,我启动了一个嵌入式Redis服务器.当我在Eclipse中启动时,一切正常,除了我希望在停止Spring Boot应用程序时停止Redis服务器.所以我设置了几个关闭钩子,但是当我从Eclipse终止应用程序时它们没有被调用.

他们是关于SO的类似问题,我创建了这个问题,希望有一个Redis解决方案.这些类似的问题也没有特定于Spring Boot.

我尝试了很多东西:

  • 春季靴子ExitCodeGenerator;
  • DisposableBean;
  • @PreDestroy;
  • 我试过ShutdownHook(在@ mp911de的回答之后)

他们都不被称为.

也许有一个Redis选项,超时,保持活着..我不知道的盒子外面的东西? 当我的Spring Boot应用程序突然停止时,如何确保Redis服务器停止

=>我看到这个嵌入式Redis用于弹簧启动,但@PreDestroy在意外杀死应用程序时才被调用.

以下是一些类似的问题:

我还在eclipse.org上看到这篇文章,讨论在从eclipse停止应用程序时如何调用shutdown hook:正常关闭Java应用程序


这是我的所有相关代码:

用于在启动时启动嵌入式 Redis服务器的组件(我尝试将其停止!!):

@Component
public class EmbeddedRedis implements ExitCodeGenerator, DisposableBean{

    @Value("${spring.redis.port}")
    private int redisPort;

    private RedisServer redisServer;

    @PostConstruct
    public void startRedis() throws IOException {
        redisServer = new RedisServer(redisPort);
        redisServer.stop();
        redisServer.start();
    }

    @PreDestroy
    public void stopRedis() { …
Run Code Online (Sandbox Code Playgroud)

java eclipse spring redis spring-boot

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

Spring MVC - 在控制器之间传递模型

我创建了一个控制器来执行一些业务逻辑并创建一个模型.如果我通过返回带有视图名称和模型的ModelAndView直接将此模型传递给视图 - 一切都运行良好.但现在我想在另一页显示结果.所以我使用"redirect:"前缀重定向到另一个控制器,但模型丢失了.

我错过了什么?

此致,Oleksandr

spring-mvc

5
推荐指数
2
解决办法
2万
查看次数

Spring AOP创建了额外的bean

我正在玩Spring AOP.

这是一个简单的课程

public class CModel extends Car {
    private double torqueMeasure = 1;

    public CModel() {
        System.out.println(" C-Model constructor");        
    }
}
Run Code Online (Sandbox Code Playgroud)

Spring配置就是这样的

<aop:config>
    <aop:aspect ref="audit">
        <aop:before pointcut="execution(* com.test.main..*(..))" method="firstControl"/>
            ...
    </aop:aspect>
</aop:config>
Run Code Online (Sandbox Code Playgroud)

现在可以; 当我添加aop:config并拦截CModel然后Spring调用CModel构造函数两次.这意味着Spring创建了2个CModel对象,对吧?

如果我删除AOP配置,那么Spring只创建一个CModel对象.

知道为什么会这样吗?

谢谢.

java aop spring spring-aop

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

如何在nginx上部署Spring Web应用程序?

我想在nginx中部署基于Spring的Web应用程序?

谁能建议我最好的方法论?

谢谢和问候Vijay

nginx spring-mvc

5
推荐指数
0
解决办法
626
查看次数

使用spring boot 1.3.1时"找不到资源'src/checkstyle/checkstyle-suppressions.xml"

maven-checkstyle-plugin不应该提供默认的config xml文件吗?运行maven时为什么会出现此错误?

我不能谷歌解决这个问题的一些解决方案,请帮我搞定,谢谢!

错误消息如下:

[错误]无法执行目标org.apache.maven.plugins:maven-checkstyle-plugin:2.16:check(checkstyle-validation)on project explorer-parent:在checkstyle执行期间失败:无法在位置找到抑制文件:src/checkstyle/checkstyle-suppressions.xml:找不到资源'src/checkstyle/checkstyle-suppressions.xml'. - > [帮助1]


附加的pom文件: 父pom 模块pom

maven spring-boot

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