如何在Linux系统中很好地配置Spring Boot应用程序打包为可执行jar作为服务?这是推荐的方法,还是应该将此应用程序转换为war并安装到Tomcat中?
目前我可以从screen
会话中运行Spring启动应用程序,这很不错,但需要在服务器重启后手动启动.
我正在寻找的是一般建议/方向或示例init.d
脚本,如果我使用可执行jar的方法是正确的.
我在junit测试中使用mockito.你怎么做一个异常发生然后断言它有(通用伪代码)
如何做这样的代码groovy
?
do {
x.doIt()
} while (!x.isFinished())
Run Code Online (Sandbox Code Playgroud)
因为groovy中没有do ... while
语法.
目前还没有'do ... while()'语法.
由于含糊不清,我们还没有增加对Groovy的支持
参考文献:
ServiceCaller
我想测试的Java类(调用)有这个:
@Autowired @Qualifier(value="serviceA")
SomeService serviceA;
@Autowired @Qualifier(value="serviceB")
SomeService serviceB;
Run Code Online (Sandbox Code Playgroud)
(有一种doWork()
方法可以检查条件并调用A或B).
如何将每个服务的模拟注入适当的变量?
我的Junit有这个:
@InjectMocks ServiceCaller classUnderTest = new ServiceCaller();
@Mock SomeService mockServiceA;
@Mock SomeService mockServiceB;
Run Code Online (Sandbox Code Playgroud)
然而,当我运行我的测试以检查在正确条件下调用的服务A/B时,我得到空指针,因为没有注入模拟.
显然它是因为对同一个接口的多重依赖(SomeService
).有没有办法在声明模拟服务时指定限定符?或者我是否需要为依赖项设置setter并设置旧的方式?
如何在不使用任何if语句的情况下从Guava Optional转换为Java Optional?
if (maybeSomething.isPresent()) {
return java.util.Optional.of(maybeSomething.get())
} else {
return java.util.Optional.empty()
}
Run Code Online (Sandbox Code Playgroud) public static void main(String... args){
then(bar()); // Compilation Error
}
public static <E extends Exception> E bar() {
return null;
}
public static void then(Throwable actual) { }
public static void then(CharSequence actual) { }
Run Code Online (Sandbox Code Playgroud)
编译结果(来自命令行javac Ambiguous.java
)
Ambiguous.java:4: error: reference to then is ambiguous
then(bar());
^
both method then(Throwable) in Ambiguous and method then(CharSequence) in Ambiguous match
1 error
Run Code Online (Sandbox Code Playgroud)
为什么这种方法含糊不清?这段代码在Java 7下成功编译!
将方法栏更改为:
public static <E extends Float> E bar() {
return null;
}
Run Code Online (Sandbox Code Playgroud)
这编译没有任何问题,但在IntelliJ Idea(无法解析方法then(java.lang.FLoat)
)中报告为错误.
此代码在Java …
我正在尝试添加org.apache.commons.lang3
到我的构建中.我已经下载了包含jar文件的目录库.
我的小组正在使用gradle来构建项目,我知道这个问题就足够了.所以我认为构建正在做的是
我想添加lang3库,但我不知道如何去做.我可以把它转储到src/main/java吗?或者我必须告诉gradle它?
这是我认为与当前build.gradle相关的内容
ext.releaseDir = "${buildDir}/release/${tpVersion.getProgramName()}"
ext.bundlesDir = "${releaseDir}/nucleus/bin/nucleus_java/bundles/"
dependencies {
compile fileTree(dir: bundlesDir, include: '*.jar')
bnd {
source sourceSets.main.java.srcDirs
include '**/*.bnd'
Run Code Online (Sandbox Code Playgroud) 如何很好地将包含一个或零个元素的列表转换为Optional?
丑陋的代码:
List<Integer> integers = new ArrayList<>();
Optional<Integer> optional = integers.size() == 0 ?
Optional.empty() :
Optional.of(integers.get(0));
Run Code Online (Sandbox Code Playgroud) 我正在尝试@Autowired
用Mockito模拟对象替换对象.通常的方法是使用Springockito使用xml:
<mockito:mock id="SomeMock" class="com.package.MockInterface" />
Run Code Online (Sandbox Code Playgroud)
目前我正在尝试使用Spring的JavaConfig来完成这项工作.突然之间,Java表达式比xml更加冗长:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class MyTestClass {
@Configuration
static class Config {
@Bean
public MockInterface somethingSpecial() {
return Mockito.mock(MockInterface.class);
}
}
@Autowired MockInterface mockObj;
// test code
}
Run Code Online (Sandbox Code Playgroud)
我发现了一个名为Springockito-annotations的库,它允许您执行以下操作:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader=SpringockitoContextLoader.class)
public class MyTestClass {
@Autowired @ReplaceWithMock MockInterface mockObj;
// test code
}
Run Code Online (Sandbox Code Playgroud)
显然,一大堆漂亮:)唯一的问题是,这种情况下加载程序不会允许我使用@Configuration
和JavaConfig其他豆类(如果我这样做,春天抱怨说没有匹配自动连接领域的考生).
你们知道如何让Spring的JavaConfig和Springockito-annotations发挥得更好吗?或者,是否有另一种创建模拟的简写?
作为一个很好的奖励,使用Springockito和xml配置,我能够模拟出具体的类而不为其依赖项提供自动装配候选(如果有的话).没有xml这是不可能的吗?
自2.5以来,我没有跟上spring框架的所有变化.我正在寻找一个4.0的示例应用程序,它具有基本的骨架应用程序,其中hibernate使用控制器和服务以4.0方式完成.
我用Google搜索并查看了弹簧网站,我认为在过去的一年左右,这个网站已经变得更糟了.谁能帮我吗?