我正在尝试在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在我的课堂上.
有任何想法吗 ?
我有来自同一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) 我有一个添加关闭钩子的方法.我需要测试(通过JUnit)调用钩子中执行的代码:
public void myMethod(){
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
... code to test ...
}
});
}
Run Code Online (Sandbox Code Playgroud)
如何在单元测试中模拟关机?
我想测试一个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) 在查找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中?这看起来更像是一种解决方法,而不是解决方案,我更愿意理解并使事情变得清晰.
感谢您的参与.
很多时候,我需要在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) 在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正确测试?
谢谢你的帮助.
我正处于应用程序开发的研究阶段.服务器端开发已经开始了,用Spring boot和Maven.现在,我正在研究开发客户端的可能选择.
我想使用Angular 2(我知道它仍然是alpha),但我真的在它的javascript和打字稿版本之间犹豫不决.我知道带有版本的实时重载javascript应该与maven spring-boot run(理论上)一起使用,这对生产力有很大帮助.我想知道是否有办法让版本的实时重新加载.有没有人设法在自己的项目中实现它?如果是的话,你是怎么做的?typescriptAngular
我还没有在maven-typescript-plugin上找到任何关于这方面的文档
构建系统也将Maven用于客户端.
编辑:有一个简单的打字稿调试方法,还是一个痛苦的?
我刚刚将我的Mac OS从Mac 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?
我正在开发一个静态站点,使用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找到。
在玩 时Spring security,我想知道CSRF应用程序注销时(跨站点请求伪造)令牌生命周期的方法。
假设用户登录并浏览我的网站。然后他退出。我是否应该使 CSRF 令牌失效(在我的情况下作为 cookie 实现,如果重要的话)?
如果不是,在安全方面有什么我应该注意的警告吗?
如果是,我该如何管理用户在应用程序上的任何进一步操作?如果没有任何CSRFToken,服务器端会禁止某些操作。那我应该生成一个新的令牌吗?
我用于Spring boot服务器端,默认情况下它似乎会使令牌无效(或者我犯了一些错误导致了这个结果......)
谢谢你的帮助。
在 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) 首先,我知道我要做的事情可以使用自定义来完成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 MVC和Jackson.
java ×5
maven ×4
spring-boot ×2
spring-mvc ×2
angular ×1
asynchronous ×1
base-url ×1
csrf ×1
debugging ×1
dependencies ×1
dictionary ×1
eclipse ×1
github-pages ×1
guava ×1
jackson ×1
javascript ×1
jboss-weld ×1
jekyll ×1
json ×1
jsr305 ×1
junit ×1
livereload ×1
mocking ×1
mockmvc ×1
promise ×1
rubymine ×1
token ×1
typescript ×1
unpack ×1
windows-7 ×1
xcode ×1
xcodebuild ×1