我有这门课
@Service
@Profile("async")
public class MyServiceImplAsync implements MyService {
..
@Async
@Override
public void printGreetings(String name) {
//do something and sleep 10 seconds
}
@Async
@Override
public Future<String> doSomething(String text) {
//do something and sleep 25 seconds
return new AsyncResult<String>(text);
}
}
Run Code Online (Sandbox Code Playgroud)
观察,两种方法使用 @Async
现在,我也有以下内容:
@Component
public class MySchedule {
..
@Scheduled(cron="*/5 * * * * ?")
public void schedule(){
logger.info("Schedule working at {}", simpleDateFormat.format( new Date() ));
this.myService.printGreetings("Manolito");
}
@Scheduled(cron="*/30 * * * * ?")
public void scheduleFuture(){
logger.info("Schedule …Run Code Online (Sandbox Code Playgroud) 我正在使用 Atom Editor + 两个有关 asciidoctor 的插件/包。
一切都按预期工作。但我有以下情况:
我有以下目录结构:
xml
figures
findOneXml.adoc
findOneXml.png
urls
findOne.adoc
Run Code Online (Sandbox Code Playgroud)
哪里findOneXml.adoc(在数字文件夹内)有
[[findOneXml]]
image::findOneXml.png[caption="Figure - " title="findOneXml"]
Run Code Online (Sandbox Code Playgroud)
通过实时预览,我可以看到图像及其各自的描述
现在 with findOne.adoc(在url文件夹中)包含以下行:
include::../figures/findOneXml.adoc[]
Run Code Online (Sandbox Code Playgroud)
我认为路径参考没问题。如果我使用其他,实时预览会显示一条关于无效或错误路径的错误消息。
但是通过实时预览,我看到图像损坏了,但我可以看到描述。
有什么问题或遗漏了什么?
即使include::./../figures/findOneXml.adoc[]失败
注意:在子/子文档中,我需要添加其他数据如何注释、提示(警告),该子文档将被其他父母多次重复使用。所以我只不需要参考图像。
谢谢
我正在与:
4.3.104.124.3.1我有这两个测试班
@Transactional
@RunWith(Parameterized.class)
@ContextConfiguration(classes={RootApplicationContext.class})
@ActiveProfiles(resolver=TestJdbcActiveProfilesResolver.class)
@TestExecutionListeners(listeners={LoggingTestExecutionListener.class}, mergeMode=MergeMode.MERGE_WITH_DEFAULTS)
public class PersonaServiceImplJdbcTest {
@Transactional
@RunWith(Parameterized.class)
@ContextConfiguration(classes={RootApplicationContext.class})
@ActiveProfiles(resolver=TestHibernateActiveProfilesResolver.class)
@TestExecutionListeners(listeners={LoggingTestExecutionListener.class}, mergeMode=MergeMode.MERGE_WITH_DEFAULTS)
public class PersonaServiceImplHibernateTest {
Run Code Online (Sandbox Code Playgroud)
两个测试类的方法代码@Test是相同的,这违反了DRY原则,这两个测试类之间的独特区别是jdbc和Hibernate配置文件与其他测试类一起工作,例如development, mysql,它在内部通过每个TestXXXActiveProfilesResolver类变体。
到目前为止,我有 2 个测试类,打破了DRY原则,按层次结构思考我将得到 3 个。
如何(如果可能)使用一个测试类,其中每次交互执行两组(或更多)配置文件,例如:
jdbc,development,mysqlHibernate,development,mysql我已经读过:
但我想避免通过Maven或 来使用命令Gradle,它可以通过类来保持控制TestXXXActiveProfilesResolver。
我在很多地方都见过
@SpringBootApplication
public class Application {
private static final Logger log =
LoggerFactory.getLogger(Application.class);
public static void main(String[] args){
SpringApplication.run(Application.class, args);
}
@Bean
public CommandLineRunner demo(UserRepository repo) {
return (args) -> {
};
}
}
Run Code Online (Sandbox Code Playgroud)
如何
@Bean
public CommandLineRunner demo(UserRepository repo) {
return (args) -> {
};
}
Run Code Online (Sandbox Code Playgroud)
返回类型的对象CommandLineRunner
它返回一个函数
(args) -> {
};
Run Code Online (Sandbox Code Playgroud)
我也无法理解语法。
有人可以帮助我理解吗
就像标题所说..
我已经阅读了这个有价值的如何在单个MessageListenerContainer中为Spring Java Config链接添加多个JMS MessageListners
这篇文章的作者正在努力
messageListenerContainer.setMessageListener(new TaskFinished());
Run Code Online (Sandbox Code Playgroud)
顺便说一句:我用
@Autowired
private ConsumerListener consumerListener;
defaultMessageListenerContainer.setMessageListener(consumerListener);
Run Code Online (Sandbox Code Playgroud)
我没有使用新的运算符.
好的,setMessageListener方法的限制是:该类必须实现MessageListener接口,我已测试并正常工作
根据23.6 JMS命名空间支持,我的问题是
如何表示以下内容:
<jms:listener destination="queue.orders" ref="orderService" method="placeOrder"/>
<jms:listener destination="queue.confirmations" ref="confirmationLogger" method="log"/>
Run Code Online (Sandbox Code Playgroud)
通过JavaConfig?
它们是简单的pojo(参见ref和method属性)
我想使用一个简单的pojo(@Component或@Service)选项而不是MessageListener对象
在DefaultMessageListenerContainer API中,没有任何东西可以解决此要求或情况.
提前致谢..
我有一个控制器工作正常,它可以注册和更新一个实体,以及如何分别创建表格以分别保存和更新实体
@RequestMapping(value="/registrar.htm", method=RequestMethod.GET)
public String crearRegistrarFormulario(Model model){
…
}
@RequestMapping(value="/{id}/actualizar.htm", method=RequestMethod.GET)
public String crearActualizarFormulario(@PathVariable("id") String id, Model model){
…
}
Run Code Online (Sandbox Code Playgroud)
直到这里我没有问题.
我的问题是关于@InitBinder
我需要使用相同的实体Deportista(运动员),一个特殊的设置来保存和更新.例如
@InitBinder
public void registrarInitBinder(WebDataBinder binder) { // register or save
logger.info(">>>>>>>> registrarInitBinder >>>>>>>>>>>>>");
…
CustomDateEditor customDateEditor = new CustomDateEditor(...
…
}
@InitBinder
public void actualizarInitBinder(WebDataBinder binder) { // update
logger.info(">>>>>>>> actualizarInitBinder >>>>>>>>>>>>>");
…
CustomDateEditor customDateEditor = new CustomDateEditor(...
…
binder.setDisallowedFields(…) //I need this only for update
}
Run Code Online (Sandbox Code Playgroud)
我看过以下内容:
这些链接中提到变通不同entities,例如 …
AspectJ我正在开始我的 Spring 之旅,尝试在3.2 中使用Spring。我正在关注《Spring in Action》一书。作者通过以下方式导入aspectJ包来使用AspectJ:
import org.aspectj.lang.annotation.Aspect
Run Code Online (Sandbox Code Playgroud)
然而使用它让我
package org.aspectj.lang.annotation does not exist
Run Code Online (Sandbox Code Playgroud)
我尝试将aspectj.jar(版本 1.8.4)导入到我的库中NetBeans,但没有任何效果。我的罐子只有几十个SPRING FRAMEWORK 3.2.3 RELEASE xxxxxx's。它仍然没有找到该包。什么可能导致此问题?这是我的 beans.xml 的开头
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
" xmlns:util="http://www.springframework.org/schema/util">
<context:component-scan base-package="heyspring">
</context:component-scan>
<aop:aspectj-autoproxy>
Run Code Online (Sandbox Code Playgroud) 这实际上是一个由两部分组成的问题。
第一:我想知道是否有办法在我刚刚创建的视图中显示信息。我在网上找不到任何类似于可用于视图的 DISPLAY Tables 查询的内容。
创建视图的查询是:
CREATE VIEW View1 AS
SELECT *
FROM CustOrder
WHERE shipToName = 'Jim Bob'
Run Code Online (Sandbox Code Playgroud)
其次,一旦我找到了如何从上面显示特定视图,我该如何找到最高的“paidPrice”(CustOrder 表中的一列)?
谢谢大家!
我正在与Spring Framework和Spring Security
关于测试
@Controller 对于具有 安全性的一组测试类,.apply(springSecurity()使用@WithUserDetails(value="something")
@Before
public void setUp(){
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
.apply(springSecurity())// <---
.build();
}
Run Code Online (Sandbox Code Playgroud)
对于没有安全性的其他测试类集,因此不使用和。@Controller .apply(springSecurity()) @WithUserDetails(value="something")
@Before
public void setUp(){
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
.build();
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,所有关于@Controller 有或没有安全的情况都可以正常工作。
问题在于@Service,当@EnableGlobalMethodSecurity定义并且@Service方法用 注释时@PreAuthorize("hasRole('ROLE_ADMIN')"),不需要安全性的所有其他测试类现在都会失败:@Service
org.springframework.security.authentication.AuthenticationCredentialsNotFoundException:
An Authentication object was not found in the SecurityContext
Run Code Online (Sandbox Code Playgroud)
当然是因为@Test …
我尝试为我的 Spring Boot 应用程序编写一些单元测试(到目前为止,它是一个仅用于用户管理的简单 CRUD 应用程序)。
@RunWith(SpringRunner.class)
@WebMvcTest(UserController.class)
@WebAppConfiguration
public class UserControllerTest {
@MockBean
private UserService UserService;
@MockBean
private UserTypeService UserTypeService;
@MockBean
private UserTrainingService UserTrainingService;
@MockBean
private TrainingService trainingService;
@MockBean
private UserService userService;
@InjectMocks
UserController UserController;
@Autowired
private MockMvc mockMvc;
private static final int USER_ID = 1;
private User User1;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mockMvc = MockMvcBuilders.standaloneSetup(UserController).build();
UserType UserType = new UserType();
UserType.setName("Regular");
// some further setup steps. Ommited for clarity
}
@Test
public void testInitUserDetailsView() throws Exception …Run Code Online (Sandbox Code Playgroud) spring ×7
java ×4
spring-3 ×3
junit ×2
spring-4 ×2
spring-boot ×2
spring-mvc ×2
asciidoc ×1
asciidoctor ×1
aspectj ×1
atom-editor ×1
mysql ×1
spring-jms ×1
sql ×1