我想调试.class文件.例如来自JDK的一些.我下载了源代码并附上了它们.
public File[] listFiles(FilenameFilter paramFilenameFilter)
{
String[] arrayOfString = list(); // now we here
if (arrayOfString == null) return null;
....
}
Run Code Online (Sandbox Code Playgroud)
然后我键入F6并移动到下一行.在那之后,我试着看看它的价值,arrayOfString但我看到以下内容:
表达视图:

情况是正常的吗?有没有办法调试?
更新1:

更新2:

更新3:

servlet 3.0异步功能之间的区别是什么:
doGet(request,response) {
Thread t = new Thread(new Runnable()
void run(){
// heavy processing
response.write(result)
}
}
t.start();
Run Code Online (Sandbox Code Playgroud)
在servlet 3.0中,如果我浪费一个线程来进行繁重的处理 - 我在容器中再赚一个线程,但是我在繁重的处理中浪费它... :(
有人可以帮忙吗?
我有集成测试(加载上下文)和单元测试一起运行.我的代码使用spring进行编译时编织.
我的问题是我声明的建议也在我的一些单元测试中运行.这会杀死单元测试的概念,这就是我想禁用它们的原因.
有什么我可以放在切入点声明,我可以调用的一些方法,一些弹簧配置,或maven命令,禁用这些建议像所有*UnitTest.java?
谢谢您的帮助.
例:
我有以下单元测试:
@RunWith(MockitoJUnitRunner.class)
public class CompanyServiceImplTest {
@Test
public void createCampaignTest() throws Exception {
when(companyDaoMock.saveCompany(any(Campaign.class))).thenReturn(77L);
Long campaignId = companyService.createCampaign(campaignMock);
assertEquals(Long.valueOf(77L), Long.valueOf(campaignId));
}
}
Run Code Online (Sandbox Code Playgroud)
以及服务方法:
@Override
@Transactional
@EventJournal(type = EventType.CAMPAIGN_CREATE, owner = EventOwner.TERMINAL_USER)
public Long createCampaign(Campaign campaign) {
return companyDao.saveCompany(campaign);
}
Run Code Online (Sandbox Code Playgroud)
方面:
@Aspect
public class EventJournalAspect {
@Autowired
private EventJournalService eventJournalService;
@Pointcut(value="execution(public * *(..))")
public void anyPublicMethod() {}
@Pointcut("within(com.terminal.service..*)")
private void inService() {}
@AfterReturning(pointcut = "anyPublicMethod() && inService() && @annotation(eventJournal) && args(entity,..)", returning = "id")
public void …Run Code Online (Sandbox Code Playgroud) 我知道如果我有元素,我想得到List/ Set/ Map这个元素我可以调用:
Collections.singleton()/ Collections.singletonList()/Collections.singletonMap()
在这种情况下,我得到不可变的集合(我不能添加/删除元素到集合).
是否有模拟获得可变集合?
我正在尝试将上传图片的功能添加到我的spring mvc应用程序中.
jsp部分:
...
<form method="POST" action="uploadImage" enctype="multipart/form-data">
<div class="load-line">
<input type="file" class="file"/>
<input type="submit" value="Upload">
...
Run Code Online (Sandbox Code Playgroud)
组态:
...
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
...
Run Code Online (Sandbox Code Playgroud)
控制器:
@RequestMapping(value="/member/createCompany/uploadImage", method=RequestMethod.POST)
public @ResponseBody String handleFileUpload(
@RequestParam("file") MultipartFile file){
String name = "image_name";
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
BufferedOutputStream stream =
new BufferedOutputStream(new FileOutputStream(new File(name + "-uploaded")));
stream.write(bytes);
stream.close();
return "You successfully uploaded " + name + " into " + name + "-uploaded !";
} catch (Exception e) {
return …Run Code Online (Sandbox Code Playgroud) 我写过以下测试:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:META-INF/dataContext.xml"},classes = Configiuration.class)
@ActiveProfiles("test")
public class CityDaoImplTest {
....
}
Run Code Online (Sandbox Code Playgroud)
我需要在调用时使用xml文件和java类bur中的配置
mvn test我在控制台中看到以下内容:
Tests in error:
initializationError(***.CityDaoImplTest): Cannot process locations AND classes for context configuration [ContextConfigurationAttributes@5bb21b69 declaringClass = '***.CityDaoImplTest', classes = '{***.Configiuration}', locations = '{classpath:META-INF/dataContext.xml}', inheritLocations = true, initializers = '{}', inheritInitializers = true, name = [null], contextLoaderClass = 'org.springframework.test.context.ContextLoader']; configure one or the other, but not both.
Run Code Online (Sandbox Code Playgroud)
如何在不重写配置的情况下修复它?
我有代码实现任意键的"锁定处理程序".给定a key,它确保一次只有一个线程可以process(或等于)密钥(这意味着调用该externalSystem.process(key)呼叫).
到目前为止,我有这样的代码:
public class MyHandler {
private final SomeWorkExecutor someWorkExecutor;
private final ConcurrentHashMap<Key, Lock> lockMap = new ConcurrentHashMap<>();
public void handle(Key key) {
// This can lead to OOM as it creates locks without removing them
Lock keyLock = lockMap.computeIfAbsent(
key, (k) -> new ReentrantLock()
);
keyLock.lock();
try {
someWorkExecutor.process(key);
} finally {
keyLock.unlock();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我明白这段代码可以导致OutOfMemoryError因为没有一张清晰的地图.
我想如何制作积累有限数量元素的地图.当超过限制时,我们应该用new替换最旧的访问元素(此代码应与作为监视器的最旧元素同步).但是我不知道怎么回调会说我超出限制.
请分享你的想法.
PS
我重读了这个任务,现在我发现我有限制,handle不能调用超过8个线程的方法.我不知道它对我有什么帮助,但我刚提到它.
PS2
通过@Boris,Spider被认为是一个简单明了的解决方案:
} finally {
lockMap.remove(key);
keyLock.unlock();
} …Run Code Online (Sandbox Code Playgroud) 我有以下JPQL请求;
@Query(value = "select req_t " +
"from TransactionRelation tr " +
"inner join tr.requestTransaction req_t " +
"inner join req_t.transactionStateHistory req_t_h " +
"inner join tr.responseTransaction resp_t " +
"inner join resp_t.transactionStateHistory resp_t_h " +
"where req_t.id >?1 " +
"and req_t.receiver.id=?2 and req_t.requestType in ?3" +
"and NOT EXISTS (select t from resp_t_h t where t.transactionState = 'REPLIED' )" +
"and EXISTS (select tt from req_t_h tt where tt.transactionState = 'WAITING_PROVIDER' )"
)
List<Transaction> queryTrabsactions(Long transactionId, Long providerId, …Run Code Online (Sandbox Code Playgroud) 我读过以下主题: 使用Spring MVC禁用Swagger
我写道:
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.project.name.controller"))
.paths(PathSelectors.ant("/api/**"))
.build()
.apiInfo(apiInfo())
.enable(false);
}
Run Code Online (Sandbox Code Playgroud)
但如果我试图访问swagger ui:localhost:8080/swagger-ui.html
我明白了

看起来不准确.我可以完全禁用此网址吗?例如404或类似的东西.
我有这门课:
package controllers;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.HashSet;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.ui.Model;
import org.springframework.web.context.WebApplicationContext;
import com.epam.hhsystem.model.candidate.Candidate;
import com.epam.hhsystem.services.CandidateService;
import com.epam.hhsystem.web.controllers.CandidateMenuController;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.context.junit4.*;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.test.web.servlet.request.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.hamcrest.Matchers.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@ContextConfiguration(locations = { "classpath:/test/BeanConfig.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
public …Run Code Online (Sandbox Code Playgroud) java ×10
spring ×4
spring-mvc ×2
testing ×2
.class-file ×1
aspectj ×1
collections ×1
concurrency ×1
debugging ×1
eclipse ×1
file-upload ×1
hibernate ×1
hql ×1
image ×1
java-8 ×1
java-ee-6 ×1
jpa ×1
jpql ×1
junit ×1
mocking ×1
servlets ×1
spring-boot ×1
spring-test ×1
swagger ×1
swagger-ui ×1
unit-testing ×1
word-wrap ×1