我正在尝试升级我的spring mvc项目以利用新的注释并摆脱我的xml.以前我在线上加载我的静态资源web.xml:
<mvc:resources mapping="/resources/**" location="/resources/" />
Run Code Online (Sandbox Code Playgroud)
现在,我正在利用WebApplicationInitializer类和@EnableWebMvc注释来启动我的服务而没有任何xml文件,但似乎无法弄清楚如何加载我的资源.
是否有注释或新配置可以在不使用xml的情况下重新获取这些资源?
我是新手,我目前正在尝试遵循这些教程,而且我已经看过很多次单引号和双引号混合.我只是想知道是否应该使用一组而不是另一组.其中一个例子是本教程的第6.12节 - 默认任务:
defaultTasks 'clean', 'run'
task clean << {
println 'Default Cleaning!'
}
task run << {
println 'Default Running!'
}
task other << {
println "I'm not a default task!"
}
Run Code Online (Sandbox Code Playgroud)
所以,我想知道我是否应该注意这些差异,或者它们是否可以互换,我可以在gradle中打印字符串时使用单引号或双引号.
我正在尝试使用Jackson来读取/写入我的POJO来自Json.截至目前,除了第三方课程外,我已经为我的课程配置并工作了.当试图读入Json我得到错误:
org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type
Run Code Online (Sandbox Code Playgroud)
经过一些快速的谷歌搜索后,似乎我的类需要一个默认的构造函数或覆盖带注释的默认构造函数.不幸的是,失败的类来自第三方库,并且该类没有默认构造函数,我显然无法覆盖代码.
所以我的问题是,我能做些什么或者我运气不好吗?
谢谢.
在我的测试中,我有以下几行:
when(client.runTask(anyString(), anyString(), isA(Iterable.class)).thenReturn(...)
Run Code Online (Sandbox Code Playgroud)
isA(Iterable.class)产生警告,它需要未经检查的转换以符合Iterable<Integer>.这是什么语法?
isA(Iterable<Integer>.class)
isA((Iterable<Integer>)Iterable.class
Run Code Online (Sandbox Code Playgroud)
不工作.
有什么建议?
我正在浏览openjdk并注意到String.equalsIgnoreCase中的一个奇怪的代码路径,特别是方法regionMatches:
if (ignoreCase) {
// If characters don't match but case may be ignored,
// try converting both characters to uppercase.
// If the results match, then the comparison scan should
// continue.
char u1 = Character.toUpperCase(c1);
char u2 = Character.toUpperCase(c2);
if (u1 == u2) {
continue;
}
// Unfortunately, conversion to uppercase does not work properly
// for the Georgian alphabet, which has strange rules about case
// conversion. So we need to make one last check …Run Code Online (Sandbox Code Playgroud) 我试图将以下Spring任务xml配置转换为纯粹基于代码/注释的版本:
<task:executor id="xyz.executor"
pool-size="${xyz.job.executor.pool.size:1-40}"
queue-capacity="${xyz.job.executor.queue.capacity:0}"
rejection-policy="CALLER_RUNS"/>
<task:scheduler id="xyz.scheduler" pool size="${xyz.job.scheduler.pool.size:4}" />
<task:annotation-driven executor="xyz.executor" scheduler="xyz.scheduler" />
<bean id='xyzProcessor' class="xyz.queueing.QueueProcessor" />
<task:scheduled-tasks scheduler="xyz.scheduler" >
<task:scheduled ref="partitioner" method="createPartitions" cron="${xyz.job.partitioner.interval:0 0 3 * * *}" />
</task:scheduled-tasks>
Run Code Online (Sandbox Code Playgroud)
根据Spring规范28.4.1(http://docs.spring.io/spring/docs/current/spring-framework-reference/html/scheduling.html),他们说要像这样从XML 转发:
<task:annotation-driven executor="myExecutor" scheduler="myScheduler"/>
<task:executor id="myExecutor" pool-size="5"/>
<task:scheduler id="myScheduler" pool-size="10"/>
Run Code Online (Sandbox Code Playgroud)
代码配置就像启用@EnableScheduling和/或@EnableAsync一样简单.
但是,我没有看到任何可以实际实例化调度程序的地方.@EnableScheduling的javadoc(http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/scheduling/annotation/EnableScheduling.html)展示了如何插入我自己创建的Executor,虽然我不确定它应该是什么类(我仍然希望能够控制池大小,队列容量和拒绝策略).它还显示了如何使用configureTasks覆盖来调度我的createPartitions方法.但是,我希望能够命名我的调度程序(以便我可以识别其线程)并控制其池大小.
所以,我想知道这些事情:
1)我可以使用哪个类来设置XML所具有的执行程序字段?
2)有没有办法创建一个我可以控制名称和池大小的调度程序实例?
说我有一个Enum如下:
package stackoverflow.models;
public enum MyEnum {
VALUE_1,
VALUE_2;
}
Run Code Online (Sandbox Code Playgroud)
然后我有一个POJO将这个Enum作为其中一个领域:
package stackoverflow.models;
public class MyPojo {
private MyEnum myEnum;
public MyEnum getMyEnum() {
return myEnum;
}
public void setMyEnum(MyEnum myEnum) {
this.myEnum = myEnum;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我应该做switch的MyPojo.getMyEnum(),我也没有需要枚举直接导入我的课:
package stackoverflow.classes;
import stackoverflow.models.MyPojo;
public class MyClass {
public static void main(final String... args) {
final MyPojo pojo = new MyPojo();
switch(pojo.getMyEnum()) {
case VALUE_1:
break;
case VALUE_2:
break;
default:
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我只是想知道为什么会这样?如果不直接导入Enum,Java如何解析Enum值?
如何将下面的函数映射到java?
VOID WriteToStruct(BOOL*状态,STRUCT_MSG RecBuff)
这个函数的作用:
1)填充结构RecBuff
2)更新状态
如何映射到Java中的布尔指针并访问函数更新的struct数据?
我有一个案例,我正在做以下事情:
final String[] columns = row.split(delimiter.toString());
Run Code Online (Sandbox Code Playgroud)
delimiter角色在哪里?
当我需要通过提供\t分隔符来基于选项卡进行拆分时,这可以正常工作.但是,当我想在管道上拆分时,我传入了一个分隔符,|这不会按预期工作.
我已经阅读了几篇关于|特殊字符如何意味着null或为空的帖子,因此它会分裂它遇到的每个字符,但是,我不想要这种行为.
我可以在我的代码中对此管道案例进行简单检查并解决问题:
if ("|".equals(delimiter.toString())) {
columns = row.split("\\" + delimiter.toString());
}
else {
columns = row.split(delimiter.toString());
}
Run Code Online (Sandbox Code Playgroud)
但我不知道是否有更简单的方法来解决这个问题.此外,是否有任何其他特殊字符的行为与|我需要考虑的一样?
我尝试开发一个 api 来打开像 word 或 pdf 这样的文件。我用 swagger 这个 API 测试,但我有下面的错误。swagger 或前面给出的参数类似这样 -> Z:\Some\Path\To\My\File.docx。
我在探索者窗口上尝试了这个 pathFile,它工作正常。
堆栈跟踪
java.io.FileNotFoundException: InputStream resource [resource loaded through InputStream] cannot be resolved to absolute file path
at org.springframework.core.io.AbstractResource.getFile(AbstractResource.java:114) ~[spring-core-4.3.12.RELEASE.jar:4.3.12.RELEASE]
at ... .DownloadDocumentResource.downloadFile(DownloadDocumentResource.java:28) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_92]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_92]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_92]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_92]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE]
Run Code Online (Sandbox Code Playgroud)
休息控制器
@RestController
public class DownloadDocumentResource {
@ResponseBody
@RequestMapping(method = RequestMethod.POST, path = {"/download"})
public ResponseEntity<InputStreamResource> downloadFile(@RequestBody String pathFile) throws IOException {
out.println(pathFile);
InputStreamResource resource = …Run Code Online (Sandbox Code Playgroud)