我从 Spring Boot 反应式迁移到 mvc。我迁移了控制器,现在我尝试迁移集成测试。
控制器的测试是这样注释的,如果我运行测试它就可以工作。
@RunWith(SpringRunner.class)
@WebFluxTest
public class MyIntegrationTest {
}
Run Code Online (Sandbox Code Playgroud)
然后我WebFluxTest像这样替换注释
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureWebTestClient
public class MyIntegrationTest {
}
Run Code Online (Sandbox Code Playgroud)
如果我运行这个测试,我就有了reactor.core.Exceptions$ReactiveException: io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: Connection refused: localhost/127.0.0.1:8080。有什么想法如何修复它吗?
当我调用.block()Java Reactor 时,如果出现错误,它会抛出ReactiveException。我需要获取包含在其中的源异常ReactiveException并重新抛出它。
这段代码有效,但是有更好的方法来实现目标吗?
try {
return myService.getObject(.....).block();
} catch (Exception e) {
throw e.getCause() != null ? e.getCause() : e;
}
Run Code Online (Sandbox Code Playgroud) 我有一个 java maven 项目,我对其进行了一些更改。这些更改破坏了测试的编译,目前,我不想修复它们(因为我不知道我的想法是否有效)。
Is there a way to altogether disable tests compilation and make my project run?
我正在学习java并尝试将一些变量从servlet传递给jsp页面.这是来自servlet页面的代码
@WebServlet("/Welcome")
public class WelcomeServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
HttpSession session = request.getSession();
session.setAttribute("MyAttribute", "test value");
// response.sendRedirect("index.jsp");
RequestDispatcher dispatcher = request.getRequestDispatcher("index.jsp");
dispatcher.forward(request, response);
}
}
Run Code Online (Sandbox Code Playgroud)
简单的jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>My Index page</title>
</head>
<body>
Index page
<br />
<%
Object sss = request.getAttribute("MyAttribute");
String a = …Run Code Online (Sandbox Code Playgroud) 我正在寻找Go的视频教程.我看到有一个类型声明和方法必须返回该类型的指针.
type testType struct {
value int
}
func (h *testType) testFunction(w http.ResponseWriter, r *http.Request) {
// we have empty body
}
Run Code Online (Sandbox Code Playgroud)
如您所见,函数体是空的,没有return语句.
我需要将http请求发送到https://some-domain.com/getsomething/?id=myID
我有url的地方,并且需要向其中添加一个查询参数。这是我的Go代码
baseUrl := "https://some-domain.com"
relativeUrl := "/getsomething/"
url, _ := url.Parse(baseUrl)
url.Path = path.Join(url.Path, relativeUrl)
// add parameter to query string
queryString := url.Query()
queryString.Set("id", "1")
// add query to url
url.RawQuery = queryString.Encode()
// print it
fmt.Println(url.String())
Run Code Online (Sandbox Code Playgroud)
在输出中,我看到以下网址: https://some-domain.com/getsomething?id=1
这是必需的: https://some-domain.com/getsomething/?id=1
您可以看到/之前没有字符?。
您是否知道无需手动字符串操作即可解决该问题?
我的环境变量是一个带有时间的字符串23:30在我的String Boot应用程序中,我想自动解析它并将结果设置为变量.
我试过这样的
@Value("#{ java.time.LocalTime.parse('${NIGHT_START_TIME}')}")
private LocalTime NIGHT_START_TIME;
Run Code Online (Sandbox Code Playgroud)
IntelliJ显示错误
无法解析变量'java'
这是日志
Unsatisfied dependency expressed through field 'NIGHT_START_TIME';
nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'LocalTime' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public?
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
Run Code Online (Sandbox Code Playgroud)
如果我读这样的变量,我看到这个值是正确的
@Value("${NIGHT_START_TIME}")
private String NIGHT_START_TIME;
Run Code Online (Sandbox Code Playgroud)
任何想法如何使其工作?
我有2个枚举
enum class Enum1{
X1, X2, X3, X4;
companion object {
val default = X2
}
}
enum class Enum2{
Y1, Y2, Y3;
companion object {
val default = Y3
}
}
Run Code Online (Sandbox Code Playgroud)
它们都有一个带default变量的伴随对象.
我有两个返回此值的方法
private fun printDefaultEnum1() : String{
return Enum1.default.toString()
}
private fun printDefaultEnum2() : String{
return Enum2.default.toString()
}
Run Code Online (Sandbox Code Playgroud)
在Kotlin中是否可以优化此代码并且只有一个接受类型并打印相应值的通用方法?
在我的 Android 应用程序中,我创建了一个临时表来对其进行一些连接。
db.execSQL("CREATE TEMPORARY TABLE pair (a INTEGER, b INTEGER);")
Run Code Online (Sandbox Code Playgroud)
你能告诉我它的可用时间是多久吗?看来,如果我重新启动应用程序,它就会消失,但如果不重新启动,它似乎会在数据库中,但会持续多长时间?
我在文档中发现它是在临时数据库中创建的。
如果“CREATE”和“TABLE”之间出现“TEMP”或“TEMPORARY”关键字,则将在临时数据库中创建新表。
我有一张地图,通过调用increaseValue方法我需要增加它的价值。在该方法中,我检查值是否存在,如果不存在,则对其进行初始化并增加它。
private final Map<String, AtomicInteger> map = new ConcurrentHashMap<>();
public void increaseValue(String key) {
map.putIfAbsent(key, new AtomicInteger(0));
map.get(key).incrementAndGet();
}
Run Code Online (Sandbox Code Playgroud)
据我记得在java 11中这两个操作可以在一行中完成,不是吗?