小编Dav*_*ave的帖子

如何仅使用JRE生成堆转储?

我们在生产环境中安装了JRE,但没有安装JDK.JRE和OS的版本如下.

[me@mymachine ~]$ java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
[me@mymachine ~]$ uname -a
Linux mymachine.mydomain.com 3.10.35-43.137.amzn1.x86_64 #1 SMP Wed Apr 2 09:36:59 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)

似乎"jmap"工具不存在于系统的任何位置,并且没有root访问权限,我无法在任何系统位置安装它.我该怎么做才能获得堆转储(即生成.hprof文件)?

另外,如果重要的话,我们正在使用JBoss 7.1.3.AS.

java heap-dump

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

为什么我的实体不会从我的二级缓存中被逐出?

我正在使用Hibernate 4.3.11.Final和Spring 3.2.11.RELEASE.我很困惑为什么我的缓存驱逐不起作用.我在DAO中设置了这个...

@Override
@Caching(evict = { @CacheEvict("main") })
public Organization save(Organization organization)
{
    return (Organization) super.save(organization);
}

@Override
@Cacheable(value = "main")
public Organization findById(String id)
{
    return super.find(id);
}
Run Code Online (Sandbox Code Playgroud)

这是我的Spring配置......

<cache:annotation-driven key-generator="cacheKeyGenerator" />

<bean id="cacheKeyGenerator" class="org.mainco.subco.myproject.util.CacheKeyGenerator" />

<bean id="cacheManager"
    class="org.springframework.cache.ehcache.EhCacheCacheManager"
    p:cacheManager-ref="ehcache"/>

<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
    p:configLocation="classpath:ehcache.xml"
    p:shared="true" />

<util:map id="jpaPropertyMap">
    <entry key="hibernate.show_sql" value="true" />
    <entry key="hibernate.dialect" value="org.mainco.subco.myproject.jpa.subcoMysql5Dialect" />
    <entry key="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory" />
    <entry key="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider" />
    <entry key="hibernate.cache.use_second_level_cache" value="true" />
    <entry key="hibernate.cache.use_query_cache" value="false" />
    <entry key="hibernate.generate_statistics" value="true" />
    <entry key="javax.persistence.sharedCache.mode" …
Run Code Online (Sandbox Code Playgroud)

spring hibernate ehcache second-level-cache evict

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

当DIV没有足够的空间但保持DIV居中时,如何制作滚动条?

我想创建一个居中的表单.

HTML:

<div id="profileContainer”>…</div>
Run Code Online (Sandbox Code Playgroud)

CSS:

#profileContainer {
  border-radius: 25px;
  background: #ffffff;
  padding: 10px;
  width: 100%;
  max-width: 760px;
  display: inline-block;
  position: fixed;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}
Run Code Online (Sandbox Code Playgroud)

问题是当屏幕垂直缩短时,表单的一部分会被隐藏,并且没有滚动条可以使其可访问:JSFiddle.

题:

我怎么出现滚动条时,单独的垂直空间不足,但请保留我的div水平居中和垂直方向时,有足够的空间?

html css scroll center scrollbars

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

如何保持选定的LI可见(未隐藏)?

我正在使用jQuery 1.12.我有一个带LI元素的UL风格.当DIV具有焦点时,我使用以下代码使用键盘上的向上或向下箭头选择这些元素...

 $(".select").bind('keydown', function(event) {
    var currentElement = $(this).find(".select-options li.selected");
    if (currentElement.length == 0) {
        currentElement = $(this).find(".select-options li")[0];
      $(currentElement).addClass("selected");
      return;
    }       // if
    var nextElement;
    switch(event.keyCode){
    // case up
    case 38:
        nextElement = $(this).find(".select-options li")[($(this).find(".select-options li").index(currentElement) - 1) % $(this).find(".select-options li").length];
        break;
    case 40:
        nextElement = $(this).find(".select-options li")[($(this).find(".select-options li").index(currentElement) + 1) % $(this).find(".select-options li").length];
      break;
    }
    $(this).find(".select-options li").removeClass("selected");
    if(nextElement !== null) {
        $(nextElement).addClass("selected");
    }
 });
Run Code Online (Sandbox Code Playgroud)

问题是,如果你不断点击向下键(例如),最终你将无法看到所选项目.如何调整内容以使所选项始终可见?说明问题的小提琴在这里 - http://jsfiddle.net/sge8g5qu/1/.

html css jquery css3 html-lists

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

有没有办法检查Ruby变量是否包含二进制数据?

我正在使用Ruby 2.4和Rails 5.我有一个名为"content"的变量文件内容.内容可能包含来自PDF文件,Word文件或HTML文件等内容的数据.有没有办法判断变量是否包含二进制数据?最后,我想知道这是PDf,Microsoft Office还是其他类型的OpenOffice文件.这个答案 - Rails:可以检查一个字符串是否是二进制文件? - 建议我可以检查变量的编码

content.encoding
Run Code Online (Sandbox Code Playgroud)

它会产生

ASCII-8BIT
Run Code Online (Sandbox Code Playgroud)

但是,在二进制数据的情况下,我注意到存在变量中存储的HTML内容也可能返回"ASCII-8BIT"作为content.encoding,因此使用"content.encoding"并不是一种万无一失的方法.告诉我我是否有二进制数据.这种方式是否存在,如果存在,它是什么?

ruby binary encoding ruby-on-rails ms-office

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

在 NestJS 中,我可以在控制器级别添加什么装饰器来将授权标头添加到我的 Swagger 文档中?

我正在使用 NestJS 7.6.11。我的控制器上有以下装饰器......

@Controller('private')
@ApiTags('MyObjects')
@ApiConsumes('application/json')
@ApiProduces('application/json')
@UseInterceptors(new JwtInterceptor())
export class MyController {
Run Code Online (Sandbox Code Playgroud)

是否有任何我可以添加的装饰器会导致生成 Swagger(OpenAPI 3)文档,以表明我的控制器中的所有方法都需要有一个“授权”标头?

编辑:作为回应,我添加了 @ApiHeader 所以我的控制器和方法看起来像

@

Controller('myendpoint')
@ApiTags('MyObject')
@ApiConsumes('application/json')
@ApiProduces('application/json')
@ApiHeader({
  name: 'authorization',
  description: 'Auth token',
})
@UseInterceptors(new JwtInterceptor())
export class MyObjectController {

...
 @Get('/:id')
  @ApiOkResponse({
    description: 'OK',
    type: Content,
  })
  @ApiBadRequestResponse()
  @ApiInternalServerErrorResponse()
  @ApiOperation({
    summary: 'Get object by id',
    description: 'Get object by id',
    operationId: 'findObjectById',
  }) 
  findObjectById(@Req() req, @Param('id') id: string): Promise<MyObject> {
Run Code Online (Sandbox Code Playgroud)

但是当生成 swagger 文档时,尽管我可以输入“授权”标头值,

在此输入图像描述

当我单击“执行”时,它不会包含在我的curl中,它生成为

curl -X GET "http://localhost:8060/myendpoint/abcdef" -H  "accept: application/json"
Run Code Online (Sandbox Code Playgroud)

swagger openapi nestjs authorization-header

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

如何让Eclipse保持控制台输出?

我在使用Java 6的Win XP上使用Eclipse Indigo.我有一个带有GWT(2.3)的Maven项目,当我启动我的项目(Run - > Web Application)时,该应用程序会抛出一些启动错误.但是,控制台只保留了错误的最后一部分,我无法分辨出是什么开始的.

http://screencast.com/t/MsgM1SuxI

请注意,在屏幕截图中,我尽可能向上滚动但仍然会切断堆栈跟踪.如何让Eclipse保存整个控制台错误日志?

谢谢, - 戴夫

eclipse console

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

如何在默认情况下选中弹簧复选框?

我正在使用Spring 3.1.0.RELEASE.我的命令对象中有这个字段...

public Set<EventFeed> getUserEventFeeds() {
    return this.userEventFeeds;
}
Run Code Online (Sandbox Code Playgroud)

在我的Spring JSP页面上,我想显示所有可能的事件源的复选框列表,然后检查复选框,如果用户在其集合中有一个.我希望在每个复选框周围都有一些特殊的HTML格式,所以我正在尝试......

<form:form method="Post" action="eventfeeds.jsp" commandName="user">
    ...
        <c:forEach var="eventFeed" items="${eventFeeds}">
        <tr>
            <td><form:checkbox path="userEventFeeds" value="${eventFeed}"/></td>
            <td>${eventFeed.title}</td>
        </tr>
        </c:forEach>
    ...
Run Code Online (Sandbox Code Playgroud)

但是,如果一个项目在集合中,则默认情况下不会检查这些项目.我该怎么做呢?这是我在控制器类中使用的活页夹...

@InitBinder
public void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(EventFeed.class, new EventFeedEditor());
}

private class EventFeedEditor extends PropertyEditorSupport {
    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        setValue(eventFeedsDao.findById(Integer.valueOf(text)));
    }

    @Override
    public String getAsText() {
        return ((EventFeed) getValue()).getId().toString();
    }
}
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc

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

如何让我的Spring-JUnit测试认为它在GenericApplicationContext中运行?

我使用Spring 3.2.6.RELEASE,JUnit 4.11DWR 3.0.0-rc2.我的问题是,在运行Spring-JUnit集成测试时,如何模拟正在运行的东西org.springframework.context.support.GenericApplicationContext

我试过这个:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({ "classpath:test-context.xml", "classpath:dwr-context.xml" })
@WebAppConfiguration
public class MyServiceIT 
{}
Run Code Online (Sandbox Code Playgroud)

我的"dwr-context.xml"文件设置为

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
       http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd">

  <dwr:configuration>
    <dwr:convert class="java.lang.StackTraceElement" type="bean"/>
  </dwr:configuration>
  <dwr:annotation-config id="annotationConfig" />
  <dwr:annotation-scan base-package="org.mainco.subco" scanDataTransferObject="true" scanRemoteProxy="true" />
  <dwr:url-mapping />
  <dwr:controller id="dwrController" debug="false" /> 

  <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="alwaysUseFullPath" value="true"/>
    <property name="urlMap">
      <map>
        <entry key="/dwr/**" value-ref="dwrController" />
      </map>
    </property>
  </bean> 
</beans>
Run Code Online (Sandbox Code Playgroud)

但是,我的所有JUnit测试最终都会因以下异常而死:

("java.lang.IllegalStateException:WebApplicationObjectSupport实例[org.directwebremoting.spring.DwrController@11297ba3]不在WebApplicationContext中运行,而是在:org.springframework.context.support.GenericApplicationContext@4e513d61")中运行.

如果我能弄明白如何欺骗系统运行,GenericApplicationContext我就会解决这个问题. …

java junit spring integration-testing unit-testing

9
推荐指数
1
解决办法
4393
查看次数

使用Spring的mockMvc,如何检查返回的数据是否包含字符串的一部分?

我正在使用Spring 3.2.11.RELEASE和JUnit 4.11.使用Spring mockMvc框架,如何检查返回JSON数据的方法是否包含特定的JSON元素?我有

    mockMvc.perform(get("/api/users/" + id))
        .andExpect(status().isOk())
        .andExpect(content().string("{\"id\":\"" + id + "\"}")); 
Run Code Online (Sandbox Code Playgroud)

但这会检查与返回的字符串的完全匹配,我宁愿检查JSON字符串是否包含我的本地字段"id"包含的值.

junit spring json return mockmvc

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