我正在使用 spring-boot 1.5.9。我创建了一个简单的 spring-boot 应用程序,它具有以下目录结构。
LibraryService.java自动装配存储库接口并具有将书籍保存到图书馆的方法。
图书馆服务.java
@Service
public class LibraryService {
private static final Logger logger = LoggerFactory.getLogger(LibraryService.class);
@Autowired
BookRepository bookRepository;
public void save(Book book){
bookRepository.save(book);
}
public long count(){
return bookRepository.count();
}
}
Run Code Online (Sandbox Code Playgroud)
下面是BookRepository界面
public interface BookRepository extends MongoRepository<Book, String> { }
Run Code Online (Sandbox Code Playgroud)
当我在测试类中自动装配时LibraryService,我发现它没有正确注入,并且出现了不满意的依赖异常。以下是 LibraryServiceTest 类
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
@DataMongoTest
public class LibraryServiceTest {
@Autowired
LibraryService libraryService;
@Test
public void testSave(){
Book aBook = new Book("Harry Potter", "J. K. Rowling");
libraryService.save(aBook);
assertEquals(1, libraryService.count());;
}
}
Run Code Online (Sandbox Code Playgroud)
我在测试类中尝试了@MockBean …
我使用 springBoot 创建了一个简单的 websocket 应用程序。我是 Mockito 的新手,我正在尝试使用 Mockito 和 junit 对以下类的行为进行单元测试。
@Component
public class TextHandler extends TextWebSocketHandler {
WebSocketSession session;
@Override
public void handleTextMessage(WebSocketSession session, TextMessage message)
throws InterruptedException, IOException {
// send message
if (session.isOpen()) {
try {
session.sendMessage(new TextMessage("Hello from the websocket"));
} finally {
session.close();
}
} else {
System.out.println("no open session available");
}
}
Run Code Online (Sandbox Code Playgroud)
我为测试包下的会话创建了一个存根,如下所示。
@Component
public class WebSocketSessionStub implements WebSocketSession{
@Override
public String getId() {
return "SESSION1";
}
@Override
public URI getUri() {
// TODO …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下脚本在Jmeter中将文件编码为Base64以测试Web服务:
String file = FileUtils.readFileToString(new File("${filepath}"), "UTF-8");
vars.put("file", new String(Base64.encodeBase64(file.getBytes("UTF-8"))));
Run Code Online (Sandbox Code Playgroud)
这对于纯文本文件很好用,而对于其他文件类型则不能正常工作。
如何使其适用于其他文件类型?
我的model.xml中有以下内容
<type name="abc:Policy">
<title>abc Policy</title>
<parent>cm:folder</parent>
<archive>true</archive>
<mandatory-aspects>
<aspect>abc:policyProperties</aspect>
</mandatory-aspects>
</type>
Run Code Online (Sandbox Code Playgroud)
abc:policyProperties 具有以下内容。
<aspect name="abc:policytProperties">
<title>abc Policy Properties</title>
<properties>
<property name="abc:dated">
<title>Dated</title>
<type>d:date</type>
</property>
</properties>
</aspect>
Run Code Online (Sandbox Code Playgroud)
用户可以将文档上传到 abc:Policy 文件夹。但是当前模型中没有对该文档的引用。如何使此文件夹中的任何文档都可以继承 abc:dated 并将其显示在 Alfresco-share 的属性中?
我是 springboot kafka 的新手,我在这篇文章之后创建了一个示例。
https://www.codenotfound.com/spring-kafka-boot-example.html
我目前使用的是 spring.kafka.version 1.1.6
我想在消息中添加自定义标题,以便我可以在标题中发送某些属性,例如:fileName、fileId
我发现您可以将 kafka 元数据设置为标题,但这不符合我的目的。
无论如何我可以做到这一点吗?如果可能的话,我很感激你能分享一个例子。
java ×3
spring-boot ×3
junit ×2
alfresco ×1
apache-kafka ×1
base64 ×1
jmeter ×1
mockito ×1
mongodb ×1
spring ×1
spring-kafka ×1
unit-testing ×1
web-services ×1