小编Rém*_*ghe的帖子

Maven Eclipse Debug"JDWP Transport dt_socket初始化失败,TRANSPORT_INIT(510)"

我正在尝试在Eclipse中调试Maven测试.当我使用maven选项maven.surefire.debug启动测试时,我收到此错误:

ERROR: transport error 202: bind failed: Address already in use
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [../../../src/share/back/debugInit.c:690]
/bin/sh: line 1: 27500 Abort trap        
Run Code Online (Sandbox Code Playgroud)

当我尝试在我的shell中启动调试时,它是一样的.

我试图添加maven选项forkMode = never,如果没有maven.surefire.debug选项,我的焊接工件会出现另一个错误:

Error loading Weld bootstrap, check that Weld is on the classpath
Run Code Online (Sandbox Code Playgroud)

但是,Weld在我的课堂上.

有任何想法吗 ?

java eclipse debugging maven jboss-weld

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

Maven:如何从同一输出目录中的工件中解压缩精确文件?

我有来自同一groupId(org.webjars)的几个工件,我需要解压缩它们,然后将所有包含的js文件复制到同一目录中.

工件存档具有层次结构(压缩为jar),如下所示:

artifact1
    - resources
        - webjars
            - ...
                - sample-1.js
                - sample-2.js
Run Code Online (Sandbox Code Playgroud)

我最后需要将每个js文件复制到没有层次结构的同一目录中,如下所示:

outputDirectory
    - sample-1.js
    - sample-2.js
    - ...
    - sample-n.js
Run Code Online (Sandbox Code Playgroud)

我能达到的结果如下:

outputDirectory
    - artifact-1
        - resources
            - webjars
                - ...
                    - sample-1.js
                    - sample-2.js
    - ...
    - artifact-m
        - resources
            - webjars
                - ...
                    - sample-n.js
Run Code Online (Sandbox Code Playgroud)

为此,我使用了maven-dependency-plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>unpack org.webjars dependencies</id>
            <goals>
                <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
            <includeGroupIds>org.webjars</includeGroupIds>
            <includes>**/*.js</includes>
            <outputDirectory>${project.build.directory}/static</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

这个插件有一个神奇的选择吗,或者我需要另一个插件来完成这项工作?

编辑:这是我最终使用的解决方案:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution> …
Run Code Online (Sandbox Code Playgroud)

dependencies unpack maven

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

JUnit4:测试一个关闭钩子

我有一个添加关闭钩子的方法.我需要测试(通过JUnit)调用钩子中执行的代码:

public void myMethod(){
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            ... code to test ...
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

如何在单元测试中模拟关机?

java junit application-shutdown

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

Spring MockMVC,Spring security和Mockito

我想测试一个Spring Boot使用的安全控制器Spring security,并使用其中的模拟.我曾尝试使用Mockito,但我认为任何嘲弄工具都应该这样做.

为了在我的测试中启用Spring安全性,我首先做了如下:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Main.class)
@TestPropertySource(value="classpath:application-test.properties")
@WebAppConfiguration
@ContextConfiguration
public class MyTest{

    protected MockMvc mockMvc;

    @Autowired
    private WebApplicationContext wac;

    @Before
    public void setUp(){
        mockMvc = MockMvcBuilders
                .webAppContextSetup(wac)
                .apply(SecurityMockMvcConfigurers.springSecurity())
                .build();
    }

    @Test
    public void doTheTest(){
        mockMvc.perform(post("/user/register")
            .with(SecurityMockMvcRequestPostProcessors.csrf())
            .content(someContent()));
    }
}
Run Code Online (Sandbox Code Playgroud)

直到那里,它运作良好.

在这一步之后,我希望添加模拟来隔离测试我的安全控制器.

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Main.class)
@TestPropertySource(value="classpath:application-test.properties")
@WebAppConfiguration
@ContextConfiguration
public class MyTest{

    protected MockMvc mockMvc;

    @Mock
    private Myservice serviceInjectedInController;

    @InjectMocks
    private MyController myController;

    @Autowired
    private WebApplicationContext wac;

    @Before
    public void setUp(){
        mockMvc = MockMvcBuilders
                .webAppContextSetup(wac) …
Run Code Online (Sandbox Code Playgroud)

mocking spring-mvc spring-security

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

为什么我需要添加神器JSR305才能使用Guava 14+?

在查找stackoverflow的信息时,我看到了一个类似于我的问题,但这里没有真正的答案.

我需要将我的maven项目从番石榴11.0.2迁移到番石榴14或更高版本(我需要RangeSet).我用依赖更新了我的maven pom:

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>14.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

然后我运行maven构建,并得到此错误:

[ERROR] xxx.java: cannot find symbol
[ERROR] symbol  : class Nonnull
[ERROR] location: package javax.annotation
Run Code Online (Sandbox Code Playgroud)

我仔细看了一下,这个注释是用JSR305提供的,其上依赖于guava 11.0.2,因为mvn存储库会报告它.

我觉得奇怪的是,番石榴14还依赖于JSR305作为mvn存储库报告.

如果我将JSR依赖项添加到我的pom,那么编译运行正常:

<dependency>
    <groupId>com.google.code.findbugs</groupId>
    <artifactId>jsr305</artifactId>
    <version>1.3.9</version>
    <scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

但是,如果guava已经依赖它,为什么我必须将此依赖项添加到我的pom中?这看起来更像是一种解决方法,而不是解决方案,我更愿意理解并使事情变得清晰.

感谢您的参与.

java jsr305 maven guava

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

如何避免这种异步懒惰模式?

很多时候,我需要在Javascript中编写这样一个懒惰的异步加载:

if (myvar != undefined){
    doSomeTreatment(myvar)
} else {
    loadMyVarAsynchronously().then(function(value){
        myvar = value
        doSomeTreatment(myvar)
    })
}
Run Code Online (Sandbox Code Playgroud)

在这里,myvar将是哈希的一些属性,而不是局部变量.loadMyVarAsynchronously以异步方式加载myvar的值(例如,a Promise或a JQuery Deferred)

是否有一种模式可以避免在此代码中写入以下两行?

doSomeTreatment(myvar)
Run Code Online (Sandbox Code Playgroud)

javascript asynchronous promise

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

如何在Spring Rest中使用MockMVC测试Map参数

Spring Rest中,我有一个RestController公开这个方法:

@RestController
@RequestMapping("/controllerPath")
public class MyController{
    @RequestMapping(method = RequestMethod.POST)
    public void create(@RequestParameter("myParam") Map<String, String> myMap) {
         //do something
    }
}
Run Code Online (Sandbox Code Playgroud)

我想有这样的方法进行测试,使用MockMVC:

// Initialize the map
Map<String, String> myMap = init();

// JSONify the map
ObjectMapper mapper = new ObjectMapper();
String jsonMap = mapper.writeValueAsString(myMap);

// Perform the REST call
mockMvc.perform(post("/controllerPath")
            .param("myParam", jsonMap)
            .andExpect(status().isOk());
Run Code Online (Sandbox Code Playgroud)

问题是我得到500 HTTP错误代码.我很确定这是因为我使用Map作为我的控制器的参数(我尝试将其更改为String并且它可以工作).

问题是:如何在我的RestController中使用Map参数,并使用MockMVC正确测试?

谢谢你的帮助.

java dictionary mockmvc spring-restcontroller

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

Spring boot,maven,AngularJS 2,打字稿和实时重新加载

我正处于应用程序开发的研究阶段.服务器端开发已经开始了,用Spring bootMaven.现在,我正在研究开发客户端的可能选择.

我想使用Angular 2(我知道它仍然是alpha),但我真的在它的javascript打字稿版本之间犹豫不决.我知道带有版本的实时重载javascript应该与maven spring-boot run(理论上)一起使用,这对生产力有很大帮助.我想知道是否有办法让版本的实时重新加载.有没有人设法在自己的项目中实现它?如果是的话,你是怎么做的?typescriptAngular

我还没有在maven-typescript-plugin上找到任何关于这方面的文档

构建系统也将Maven用于客户端.

编辑:有一个简单的打字稿调试方法,还是一个痛苦的?

maven livereload typescript spring-boot angular

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

如何用xcode-select选择XCode 3.2.6?

我刚刚将我的Mac OSMac OS升级到10.9.3 到10.6.8.我安装了XCode 3.2.6.对于新开发,我需要安装XCode 4.5.2.

在maven构建中,我调用xcodebuild来构建一些C++项目.问题是我需要xcodebuild 3.2.6来构建某些项目,而xcodebuidl 4.5.2需要一些新项目.

我需要能够即时选择xcodebuild版本来启动项目构建.我看到xcode-select可以帮助我这样做,但是我在使用xcode-select来选择xcodebuild 3.2.6时遇到困难.

考虑我的XCode 4.5.2安装在/Applications/Xcode.app,使用命令

sudo xcode-select -switch /Applications/Xcode.app
Run Code Online (Sandbox Code Playgroud)

做的工作,如

xcodebuild -version
Run Code Online (Sandbox Code Playgroud)

输出

Xcode 4.5.2
Build version 4G2008a
Run Code Online (Sandbox Code Playgroud)

考虑到我的XCode 3.2.6/Developer/Applications/Xcode.app,我的问题是,为什么这个命令不起作用?

sudo xcode-select -switch /Developer/Applications/Xcode.app
Run Code Online (Sandbox Code Playgroud)

它输出

xcode-select: error: invalid developer directory '/Developer/Applications/Xcode.app'
Run Code Online (Sandbox Code Playgroud)

我能找到的唯一解决方法是使用绝对路径来使用xcodebuild 3.2.6,但这很棘手:

/Developer/usr/bin/xcodebuild
Run Code Online (Sandbox Code Playgroud)

是否有一种干净的方法来选择xcodebuild 3.2.6 xcode-select?

xcode xcodebuild osx-mavericks

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

Jekyll 中 localhost 和 github 页面的 Baseurl 行为不同

我正在开发一个静态站点,使用Jekyll, 部署在github pages. 我在使用配置文件中的 baseurl 时遇到问题。这是我的摘录_config.yml

baseurl: "/blog"
url: "http://remidoolaeghe.github.io"
Run Code Online (Sandbox Code Playgroud)

当在http://localhost:4000/blog/本地运行时,一切都很好。找到 html 页面,加载资源(图像、css、js)并将其应用到页面上。

一旦部署在 上Github Pages,我希望该站点可以在:http://remidoolaeghe.github.io/blog 但实际的 URL 是http://remidoolaeghe.github.io

Jekyllon似乎没有使用 baseurl Github Pages。HTML 页面不在预期的 URL 处,任何资源(css、图像等)也不在预期的 URL 处。浏览器不会加载任何基于 baseurl 的内容,如下所示:

在此输入图像描述

我已经检查过使用过的Jekyll version. Github Pages我使用与(2.4.0)相同的方法。

我错过了什么吗?

我的仓库可以在这里Github找到。

base-url jekyll github-pages

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

注销后的 CSRF 令牌生命周期

在玩 时Spring security,我想知道CSRF应用程序注销时(跨站点请求伪造)令牌生命周期的方法。

假设用户登录并浏览我的网站。然后他退出。我是否应该使 CSRF 令牌失效(在我的情况下作为 cookie 实现,如果重要的话)?

如果不是,在安全方面有什么我应该注意的警告吗?

如果是,我该如何管理用户在应用程序上的任何进一步操作?如果没有任何CSRFToken,服务器端会禁止某些操作。那我应该生成一个新的令牌吗?

我用于Spring boot服务器端,默认情况下它似乎会使令牌无效(或者我犯了一些错误导致了这个结果......)

谢谢你的帮助。

csrf token spring-security spring-boot

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

在 RubyMine 中执行测试导致 Windows 7 上的“未初始化常量 Spring::Client::Run::UNIXSocket”

在 RubyMine 中,我尝试在调试中运行测试(相当于rails test,但在 RubyMine 中使用调试模式)。我在 RubyMine 控制台中得到这个日志:

Testing started at 08:44 ...
C:\Ruby23-x64\bin\ruby.exe C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/ruby-debug-ide-0.7.0.beta4/bin/rdebug-ide --disable-int-handler --evaluation-timeout 10 --evaluation-control --time-limit 100 --memory-limit 0 --rubymine-protocol-extensions --port 55232 --host 0.0.0.0 --dispatcher-port 55233 -- C:/Users/[ANONYMOUS]/bin/rails test
Fast Debugger (ruby-debug-ide 0.7.0.beta4, debase 0.2.2, file filtering is supported) listens on 0.0.0.0:55232
Uncaught exception: uninitialized constant Spring::Client::Run::UNIXSocket
Did you mean?  Socket
               IPSocket
               UDPSocket
    C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/client/run.rb:26:in `connect'
    C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/client/run.rb:31:in `call'
    C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
    C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/client/rails.rb:24:in `call'
    C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
    C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
    C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
    C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
    C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
    C:/Ruby23-x64/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:68:in …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails rubymine windows-7

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

在Spring MVC中使用Jackson将Map序列化为一对夫妇

首先,我知道我要做的事情可以使用自定义来完成JsonSerializer,但我想知道是否有更少的样板代码解决方案.

Spring MVC,我想将序列Map化为一对夫妇.假设我想回复这样一个Map:

Map<String, String> res = new HashMap<>();
res.put("key1", "value1");
res.put("key2", "value2");
Run Code Online (Sandbox Code Playgroud)

默认的序列化结果将JSON如下所示:

{key1: value1, key2: value2}
Run Code Online (Sandbox Code Playgroud)

有没有办法让这样的东西,而不使用自定义JsonSerializer

[{key: "key1", value: "value1"}, {key: "key2", value: "value2"}]
Run Code Online (Sandbox Code Playgroud)

我正在使用Spring-Boot 1.3默认版本的Spring MVCJackson.

java json spring-mvc jackson

3
推荐指数
1
解决办法
2699
查看次数