国家图书馆wifi密码码是什么,在线急等

Spring boot 1.4.2 单元测试配置
时间: 19:18:18
&&&& 阅读:252
&&&& 评论:
&&&& 收藏:0
标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&新版较旧版简化了很多
直接在测试类上添加
@RunWith(SpringRunner.class)
@SpringBootTest(classes = 自己的启动类, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
同事注入&TestRestTemplate类 和通过&@LocalServerPort注解注入当前的端口号
具体测试代码如下:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ServerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class Test {
@LocalServerPort
private int
private URL
private Gson gson = new Gson();
@Autowired
private TestRestTemplate restT
public void setUp() throws Exception {
this.base = new URL("http://localhost:" + port + "/");
public void test() {
ResponseEntity&String& test = this.restTemplate.getForEntity(
this.base.toString() + "/test", String.class, "test");
System.out.println(test.getBody());
&controller
@RestController
@RequestMapping("/test")
public class ProcessInstanceController {
@RequestMapping(value = "", method = RequestMethod.GET)
public String test() {
return "Greetings from Spring Boot!";
ServerApplication:
@SpringBootApplication
public class ServerApplication extends SpringBootServletInitializer implements CommandLineRunner {
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ServerApplication.class);
public static void main(String[] args) throws IOException {
SpringApplication.run(ServerApplication.class, args);
public void run(String... strings) throws Exception {
System.out.println("初始化。。。。。。。。。。。。");
&标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&原文:/ButterFuture/p/6098692.html
教程昨日排行
&&国之画&&&& &&&&&&
&& &&&&&&&&&&&&&&
鲁ICP备号-4
打开技术之扣,分享程序人生!2743人阅读
J2EE(190)
Found an interesting spring annotation, looks handy for some simple tests
Code example from the reference [1]:
import org.slf4j.L
import org.slf4j.LoggerF
import org.springframework.beans.factory.annotation.A
import org.mandLineR
import org.springframework.boot.SpringA
import org.springframework.boot.autoconfigure.SpringBootA
import org.
@SpringBootApplication
public class Application {
private static final Logger log = LoggerFactory.getLogger(Application.class);
@Component
static class Runner implements CommandLineRunner {
@Autowired
private BookRepository bookR
public void run(String... args) throws Exception {
(&.... Fetching books&);
(&isbn-1234 --&& + bookRepository.getByIsbn(&isbn-1234&));
(&isbn-1234 --&& + bookRepository.getByIsbn(&isbn-1234&));
(&isbn-1234 --&& + bookRepository.getByIsbn(&isbn-1234&));
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
Reference:
[1]&https://spring.io/guides/gs/caching/
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:370477次
积分:6271
积分:6271
排名:第3391名
原创:297篇
转载:18篇
评论:25条
(1)(3)(4)(2)(7)(3)(5)(1)(1)(3)(8)(6)(8)(9)(3)(6)(6)(2)(14)(6)(7)(9)(11)(8)(1)(1)(10)(6)(11)(1)(5)(7)(2)(5)(6)(6)(10)(3)(2)(5)(2)(51)(20)(5)(3)(1)(1)(7)(2)(8)Spring Boot 启动加载数据 CommandLineRunner
实际应用中,我们会有在项目服务启动的时候就去加载一些数据或做一些事情这样的需求。
为了解决这样的问题,Spring Boot 为我们提供了一个方法,通过实现接口 CommandLineRunner 来实现。
很简单,只需要一个类就可以,无需其他配置。
创建实现接口 CommandLineRunner 的类
package org.springboot.sample.
import org.mandLineR
import org.
* 服务启动执行
http://blog.csdn.net/catoop/
@Component
public class MyStartupRunner1 implements CommandLineRunner {
public void run(String... args) throws Exception {
System.out.println(&&&&&&&&&&&&&&&&服务启动执行,执行加载数据等操作&&&&&&&&&&&&&&);
Spring Boot应用程序在启动后,会遍历CommandLineRunner接口的实例并运行它们的run方法。也可以利用@Order注解(或者实现Order接口)来规定所有CommandLineRunner实例的运行顺序。
如下我们使用@Order 注解来定义执行顺序。
package org.springboot.sample.
import org.mandLineR
import org.springframework.core.annotation.O
import org.
* 服务启动执行
http://blog.csdn.net/catoop/
@Component
@Order(value=2)
public class MyStartupRunner1 implements CommandLineRunner {
public void run(String... args) throws Exception {
System.out.println(&&&&&&&&&&&&&&&&服务启动执行,执行加载数据等操作
&&&&&&&&&&&&&&);
package org.springboot.sample.
import org.mandLineR
import org.springframework.core.annotation.O
import org.
* 服务启动执行
http://blog.csdn.net/catoop/
@Component
@Order(value=1)
public class MyStartupRunner2 implements CommandLineRunner {
public void run(String... args) throws Exception {
System.out.println(&&&&&&&&&&&&&&&&服务启动执行,执行加载数据等操作
&&&&&&&&&&&&&&);
启动程序后,控制台输出结果为:
&&&&&&&&&&&&&&&服务启动执行,执行加载数据等操作
&&&&&&&&&&&&&
&&&&&&&&&&&&&&&服务启动执行,执行加载数据等操作
&&&&&&&&&&&&&
根据控制台结果可判断,@Order 注解的执行优先级是按value值从小到大顺序。102. Spring Boot之CommandLineRunner和ApplicationRunner【从零开始学Spring Boot】
时间: 18:06:22
:在有【Spring Boot加载数据CommandLineRunner】中了CommandLineRunner的使用,说实现ApplicationRunner也可以,那么本节就是要介绍ComandLineRunner和ApplicationRunner和使用。
$T.total > 0 && $T.page <= $T.pageNum}
{#foreach $T.data as r}
{$T.r.formt_tm}{#if $T.r.nickname}{#else}匿名{#/if}
{$T.r.content}
{#if $T.page > 1 && $T.pageNum > 1)
$T.s_num > 2}
{#for index = $T.s_num to $T.e_num}
$T.pageNum > $T.pageNavSize+ 2 && $T.s_num != $T.pageNum - $T.pageNavSize}
{#if $T.pageNum > 1}
{#if $T.pageNum != $T.page && $T.pageNum > 1}
<a href="javascript:void(0);" page="{$T.page 下一页
您的回应...
也许你感兴趣
(window.slotbydup=window.slotbydup || []).push({
id: '3465635',
container: s,
size: '120,240',
display: 'float'
(C)2012 本站提供的内容来源于广大网络用户,我们不保证内容的正确性。如果转载了您的内容,希望删除的请联系我们!SpringBoot 非 Web 项目运行 | Sunshow Life
Categories

我要回帖

更多关于 浦东图书馆有wifi吗 的文章

 

随机推荐