<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
这将为您的应用程序添加几个有用的端点.其中之一是/健康.当您启动应用程序并导航到/ health端点时,您将看到它已返回一些数据.
{
"status":"UP",
"diskSpace": {
"status":"UP",
"free":56443746,
"threshold":1345660
}
}
Run Code Online (Sandbox Code Playgroud)
如何在spring boot health中添加自定义运行状况检查?
勉强的是,这段小代码抛出了上面提到的Exception.另外,查看网络上发布的代码似乎是正确的:
import java.util.ArrayList;
import java.util.Iterator;
public class IteratorTest {
ArrayList<Integer> arr = new ArrayList<Integer>();
Iterator i = arr.iterator();
public void show() {
arr.add(2);
arr.add(5);
arr.add(9);
while(i.hasNext()){
System.out.println(i.next());
}
}
}
Run Code Online (Sandbox Code Playgroud)
有什么建议?谢谢
我有像下面的json字符串
[
{
"topic": "inputTopic",
"key": "0",
"message": "test",
"partition": 0,
"offset": 0
},
{
"topic": "inputTopic",
"key": "0",
"message": "test",
"partition": 0,
"offset": 1
},
{
"topic": "inputTopic",
"key": "0",
"message": "test",
"partition": 0,
"offset": 2
},
{
"topic": "inputTopic",
"key": "0",
"message": "test",
"partition": 0,
"offset": 3
},
{
"topic": "inputTopic",
"key": "0",
"message": "test",
"partition": 0,
"offset": 4
},
{
"topic": "inputTopic",
"key": "0",
"message": "test",
"partition": 0,
"offset": 5
},
{
"topic": "inputTopic",
"key": "0",
"message": …
Run Code Online (Sandbox Code Playgroud) 在Spring MVC + Jackson(Java)中,我可以拥有:
我的对象(Java)
public class Project {
private long id;
private String self;
private String key;
private String name;
//Getters and Setters
}
Run Code Online (Sandbox Code Playgroud)
Spring MVC控制器
...
@RequestMapping(value="/doSomething", method=RequestMethod.POST)
public String doSomething(@RequestBody Project project) {
System.out.println(project.getName());
return "myPage";
}
...
Run Code Online (Sandbox Code Playgroud)
然后,我可以发送一个json:
{"id": "exampleId", "name": "exampleName","self": "url","key": "key"}
Run Code Online (Sandbox Code Playgroud)
并自动转换为我的对象.在Python上,我有我的对象类.Flask中有些东西我可以打电话:
烧瓶控制器
@app.route('/doSomething', methods=['POST'])
def do_something(project):
print project.name
return "myPage"
Run Code Online (Sandbox Code Playgroud)
我的对象(Python)
class Project():
id=None
name=None
url=None
key=None
Run Code Online (Sandbox Code Playgroud)
基本上,我想在Flask上收到我的JSON并且已经转换为我的Object.我想避免这样做:
class Project(object):
def __init__(self, id, url, name, key):
self.id = id
self.url = url …
Run Code Online (Sandbox Code Playgroud) 我在src / main / resources目录下有多组属性文件smtp,db和常用设置,我的项目是maven项目jar打包。我想从jar构建中排除所有这些属性文件,并将所有这些属性文件放置到target / conf文件夹中。现在,我想在执行应用程序jar时将所有这些配置文件提供给jar。如何实现呢?我在pom.xml文件中做了几件事,以排除所有这些属性,现在无法将它们提供给生成的jar。这是为了排除src / main / resources内容
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>*.properties</exclude>
</excludes>
<filtering>false</filtering>
</resource>
</resources>
Run Code Online (Sandbox Code Playgroud)
Spring Boot插件配置
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
Maven资源插件可将所有资源文件放置在target / conf文件夹下
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target/conf</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud) 我试图模仿JSONArray,并尝试通过抑制构造函数.但是没有一个解决方案适合我.
JSONArray mockJSONArray=PowerMokcito.mock(JSONArray.class);,
whenNew(JSONArray.class).withNoArguments().thenReturn(mockJSONArray);
whenNew(JSONArray.class).withArguments(anyObject()).thenReturn(mockJSONArray);
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙解决这个问题吗?提前致谢
我正在创建一个 Spring MVC 控制器测试。编译器以粗体显示以下方法的错误。我的代码中是否缺少一些库或其他东西?有什么建议?
我正在使用以下依赖项:
Run Code Online (Sandbox Code Playgroud)<dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>3.2.3.RELEASE</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> </dependency> <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-library</artifactId> <version>1.3</version> <scope>test</scope> </dependency>
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MockMvcBuilder;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import com.zerosolutions.view.form.LoginCredentials;
@RunWith(value=SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration("classpath:dispatcher-servlet.xml")
public class TestingFrontController {
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
@Before
public void setUp(){
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
}
@Test
public void getLoginSignupPage() throws Exception{
this.mockMvc.perform(**get**("/"))
.andExpect(status().isOk()) …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 POC 应用程序中使用可配置的 JSON 日志logback-logstash
编码器在 POC 应用程序中配置可配置的 JSON 日志。尽管我已经定义了所有建议的依赖项,并将日志记录配置减少为只有一个记录器和附加程序(以尝试隔离问题),但我仍然收到“无法找到附加程序 x。您是在上面还是下面定义的......”
我尝试逐步删除所有其他记录器/附加器,直到只剩下“找不到”的记录器/附加器。我多次检查了附加程序在记录器定义中引用之前是否已定义。我目前正在运行测试,因此我创建了一个显式的 logback-tests.xml,其配置与 logback.xml 相同。我最初已经在内部设置了所有依赖项,但按照 logback-logstash 编码器文档中的说明,我最好让它们由 dependencyManagement 管理
依赖项:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
</properties>
...
<logback.jackson.json>0.1.5</logback.jackson.json>
<logstash-logback-encoder.version>5.2</logstash-logback-encoder.version>
<ch.qos.logback.version>1.2.3</ch.qos.logback.version>
</properties>
<dependencyManagement>
...
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${ch.qos.logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${ch.qos.logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
<version>${ch.qos.logback.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
...
<!-- ======= -->
<!-- Logging -->
<!-- ======= -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback.contrib</groupId>
<artifactId>logback-jackson</artifactId>
<version>${logback.jackson.json}</version>
</dependency>
<dependency> …
Run Code Online (Sandbox Code Playgroud) 我使用Hibernate 3.6.8.这是我的表格:
CREATE TABLE UTILIZATION (
ID BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY
...
FK_WORKCATEGORY SMALLINT,
CONSTRAINT PK_UTILIZATION PRIMARY KEY ( ID));
CREATE TABLE DB2ADMIN.WORKCATEGORY(
ID SMALLINT NOT NULL,
DESCRIPTION VARCHAR(50),
CONSTRAINT PK_WORKCATEGORY PRIMARY KEY(ID));
ALTER TABLE UTILIZATION ADD FOREIGN KEY (FK_WORKCATEGORY) REFERENCES WORKCATEGORY(ID);
Run Code Online (Sandbox Code Playgroud)
我的Pojos:
@Entity
@Proxy(proxyClass=IWorkCategory.class)
@Table(name="WORKCATEGORY")
public class WorkCategory extends BoBase implements Serializable, IWorkCategory{
@Id
private Integer Id;
private String description;
@Override
public Serializable getId() {
return Id;
}
@Override
public void setId(Serializable id) {
Id …
Run Code Online (Sandbox Code Playgroud) java ×3
spring-boot ×3
spring ×2
android ×1
annotations ×1
flask ×1
hibernate ×1
iterator ×1
json ×1
jsonpath ×1
maven ×1
mockmvc ×1
powermock ×1
powermockito ×1
python ×1
spring-mvc ×1
spring-test ×1
unit-testing ×1
while-loop ×1