小编chr*_*leu的帖子

Heroku上的Node.js Web Socket H15空闲连接超时

我们在Heroku上运行一个Node.js和Express应用程序,它将ws库用于实时Web套接字.下面是我们看到的众多H15超时的屏幕截图.

在此输入图像描述

我已经读过Heroku在55秒后终止任何空闲连接,但是当连接打开时,我们的套接字每5秒来回发送一次乒乓球.一段服务器代码如下:

var _this = this;

this.server.on('connection', function(ws){

    // check for a ping, respond with pong
    ws.on('message', function(data){
        data = data.toString('utf8');
        if (data === PING) {
            ws.send(PONG);
        }
    });

    ws.on('close', function(err){
        TL.logger.info('Socket closed: '+path);
        _this.sockets = _.filter(_this.sockets, function(_ws){
            return ws != _ws;
        });
    });

    ws.on('error', function(err){
        TL.logger.info('Socket error: '+path);
        _this.sockets = _.filter(_this.sockets, function(_ws){
            return ws != _ws;
        });
    });

    _this.sockets.push(ws);
});
Run Code Online (Sandbox Code Playgroud)

这是chrome中客户端插槽的图片:

在此输入图像描述

任何想法是如何防止空闲连接?

timeout heroku websocket node.js express

14
推荐指数
1
解决办法
2628
查看次数

git"我们添加"是什么意思?

经过git rebase我的合并冲突解决.我对"由我们添加"的含义感到困惑A.java.是什么阻止它被自动添加/暂存为新文件C.java

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   com/company/C.java

Unmerged paths:
  (use "git reset HEAD <file>..." to unstage)
  (use "git add <file>..." to mark resolution)

        added by us:     com/company/A.java
        both modified:   com/company/B.java
Run Code Online (Sandbox Code Playgroud)

git版本2.5.1.windows.1

git git-rebase

13
推荐指数
1
解决办法
5626
查看次数

Spring MVC:如何解析Web应用程序中根"JSP"文件夹的子目录的路径

使用SpringMVCs viewResolvers解析不在Web应用程序的根JSP目录中的JSP文件的路径的简单方法是什么?例如,假设我们有以下Web应用程序结构:

web-app
  |-WEB-INF
    |-jsp
      |-secure
        |-admin.jsp
        |-admin2.jsp
      index.jsp
      login.jsp
Run Code Online (Sandbox Code Playgroud)

我想使用一些开箱即用的组件来解析jsp根文件夹和安全子目录中的JSP文件.我有一个*-servlet.xml文件定义:

一个开箱即用的InternalResourceViewResolver:

 <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
  <property name="prefix" value="/WEB-INF/jsp/"></property>
  <property name="suffix" value=".jsp"></property>
 </bean>
Run Code Online (Sandbox Code Playgroud)

处理程序映射:

<bean id="handlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
 <property name="mappings">
  <props>
   <prop key="/index.htm">urlFilenameViewController</prop>
   <prop key="/login.htm">urlFilenameViewController</prop>
   <prop key="/secure/**">urlFilenameViewController</prop>
  </props>
 </property>
</bean>
Run Code Online (Sandbox Code Playgroud)

一个开箱即用的UrlFilenameViewController控制器:

<bean id="urlFilenameViewController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController">
</bean>
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是无法解析对安全目录中的JSP的请求,因为jspViewResolver只有前缀定义为/jsp/和不定义/jsp/secure/.

有办法处理像这样的子目录吗?我宁愿保留这种结构,因为我也试图利用Spring Security并在子目录中拥有所有安全页面是一种很好的方法.

可能有一种简单的方法来实现这一点,但我是Spring和Spring MVC框架的新手,所以任何指针都会受到赞赏.

spring-mvc

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

如何使用Hibernate,MySQL Application中的import.sql文件将默认数据插入表中

我正在使用Spring MVC(版本3.1),Hibernate(版本3.5)和MySQL开发应用程序.在这个应用程序中,我每次运行应用程序时都会创建一个数据库模式.我想使用import.sql脚本文件将一些默认数据插入到几个表中.为此,我在root中创建了import.sql脚本,并在hibernate中使用以下语句.CFG.xml文件.

<property name="hibernate.hbm2ddl.auto">create</property> 
<property name="hibernate.hbm2ddl.import_files">import.sql</property>
<property name="connection.autocommit">true</property>
Run Code Online (Sandbox Code Playgroud)

但是我没有成功将默认数据插入表中.

请指导我.

mysql import hibernate spring-mvc maven

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

jQuery递归ajax poll使用setTimeout来控制轮询间隔

$(document).ready(function() {
    (function poll() {
        setTimeout(function() {
            $.ajax({
                url: "/project1/api/getAllUsers",
                type: "GET",
                success: function(data) {
                    console.log("polling");
                },
                dataType: "json",
                complete: poll,
                timeout: 5000
            }), 5000
        });
    })();
});?
Run Code Online (Sandbox Code Playgroud)

这只是保持执行速度与服务器响应速度一样快,但我希望它只会每5秒轮询一次.有什么建议?

编辑:我应该补充,请求完成后5秒钟会更好.

ajax jquery ajax-polling

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

Spring数据和neo4j的正确注释配置是什么

我正在尝试使用Neo4j配置一个@configuration类的Spring数据,但我找不到任何关于如何正确执行此操作的参考资料,而且我在下一个问题后遇到了一个问题.以下是我到目前为止拼凑的内容:

package reservation.configuration;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.config.EnableNeo4jRepositories;
import org.springframework.data.neo4j.repository.GraphRepositoryFactory;
import org.springframework.data.neo4j.support.Neo4jTemplate;
import org.springframework.data.neo4j.support.mapping.Neo4jMappingContext;

@Configuration
@EnableNeo4jRepositories("reservation.repository.neo4j")
public class Neo4jConfig {

    private static final String STORE_ID = "helloworld";

    @Bean
    public GraphDatabaseService graphDatabaseService() {
        return new EmbeddedGraphDatabase(STORE_ID);
    }

    @Bean
    public Neo4jTemplate neo4jTemplate() {
        return new Neo4jTemplate(graphDatabaseService());
    }

    @Bean
    public GraphRepositoryFactory graphRepositoryFactory() {
        return new GraphRepositoryFactory(neo4jTemplate(), neo4jMappingContext());
    }

    @Bean
    public Neo4jMappingContext neo4jMappingContext() {
        return new Neo4jMappingContext();
    }
}
Run Code Online (Sandbox Code Playgroud)

启动应用程序时的例外情况如下.有什么建议?

java.lang.IllegalStateException: No persistence exception translators found in …
Run Code Online (Sandbox Code Playgroud)

spring-annotations spring-data-neo4j

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

在Spring 3中注册关闭钩子的正确方法是什么?

有关如何在Java应用程序中嵌入Neo4j的教程建议注册一个关闭钩子,如下所示:

Runtime.getRuntime().addShutdownHook( new Thread() {
    // do shutdown work here
});
Run Code Online (Sandbox Code Playgroud)

我想知道放置此代码的最佳位置 - 或者实际上在Spring启动时需要运行一次的任何代码.这只是一个用init方法注册bean并将代码放入其中的情况吗?

我有兴趣知道这一点,更具体地说,当他们在Spring应用程序中使用嵌入式Neo4j时,其他人如何注册了一个关闭钩子.

spring neo4j

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

如何以一种方法而不是另一种方法正确注入Spring Environment?

neo4jDatabase()很好,但是environmentgraphDatabaseService()...中为什么总是为空?

@Configuration
@PropertySource("classpath:/neo4j.properties")
@EnableNeo4jRepositories("reservation.repository.neo4j")
public class Neo4jConfig extends Neo4jConfiguration {

    @Inject
    Environment environment;

    @Bean(initMethod = "setupDb")
    public Neo4jDatabase neo4jDatabase() {
        // Environment fine here...
        return new Neo4jDatabase(this.environment.getProperty("data.file.path"));
    }

    @Bean(destroyMethod = "shutdown")
    public GraphDatabaseService graphDatabaseService() {
        if (environment == null) {
            // Always gets here for some reason...why?
            return new EmbeddedGraphDatabase("/Temp/neo4j/database");
        } else {
            return new EmbeddedGraphDatabase(this.environment.getProperty("database.path"));
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

版本:Spring 3.2.0.RELEASE,spring-data-neo4j 2.1.0.RELEASE。

spring spring-annotations spring-data-neo4j

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

撤消git reset - hard origin/master

在当地主分公司工作:

git commit -m "Lots of important commits"
git reset --hard origin/master
Run Code Online (Sandbox Code Playgroud)

如何检索由于git重置(从远程)丢失的提交?

编辑:请注意,这不是关于检索未提交的更改.

git git-reset

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

Spring Security:即使成功登录后也无法访问目标页面

Spring版本:2.5.6 SEC01
Spring Security版本:3.0.0 RC1

我正在尝试将Spring Security与Spring MVC应用程序集成.安全部分主要基于Spring Security附带的示例应用程序.我已经定义了一些需要特定角色来访问它们的页面,并且正如预期的那样,当访问它们而不登录登录页面时(我已经定义了我自己的登录页面).问题是,即使我输入正确的用户名和密码,我也会被扔回登录页面.我不完全确定这是一个Spring Security问题还是Spring MVC问题,但我们先试试前者.我有记录的请求,所以也许更熟悉他们的人将能够发现一些东西.

有很多日志记录(比一个帖子允许的更多)所以我只包括了最有趣的一点.根据我的理解,用户'rod'的登录成功,一切似乎都很好,直到时间14:30:28,222的行,我看到Previously Authenticated: org.springframework.security.authentication.AnonymousAuthenticationToken@9055c2bc: Principal: anonymousUser;...,从那时起,用户被认为是匿名的.

输入正确的用户名和密码后,这是调试,导致返回登录页面:

14:30:28,192 DEBUG FilterChainProxy:176 - Converted URL to lowercase, from: '/j_spring_security_check'; to: '/j_spring_security_check'
14:30:28,192 DEBUG FilterChainProxy:183 - Candidate is: '/j_spring_security_check'; pattern is /**; matched=true
14:30:28,192 DEBUG FilterChainProxy:351 - /j_spring_security_check at position 1 of 12 in additional filter chain; firing Filter: 'org.springframework.security.web.access.channel.ChannelProcessingFilter@2a4e37fb'
14:30:28,193 DEBUG DefaultFilterInvocationSecurityMetadataSource:177 - Converted URL to lowercase, from: '/j_spring_security_check'; to: '/j_spring_security_check'
14:30:28,193 DEBUG DefaultFilterInvocationSecurityMetadataSource:204 - Candidate is: '/j_spring_security_check'; …
Run Code Online (Sandbox Code Playgroud)

login spring-mvc spring-security

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