我正在尝试下载一个内部仓库的jar,我已经在tomcat下,然后将其安装到我当地的maven仓库.
jar文件可以在以下路径中找到:http://10.11.250.14/strepo/ext/JSErrorCollector-0.2.jar
我编辑我的pom.xml提供内部repo的链接,并在pom中添加依赖,但maven无法下载thre jar.
<repositories>
<repository>
<id>internal.repo</id>
<url>http://10.11.250.14/strepo/ext/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.JS</groupId>
<artifactId>JSErrorCollector</artifactId>
<version>0.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
你能帮助我吗?
这可能是一个简单的问题,可能会有这类问题的重复,但我无法在任何地方找到答案.我想通过在Java中推断方法的返回类型来完成变量的类型.例如,
users = userService.findAllUsers()//This method returns List<User> objects
Run Code Online (Sandbox Code Playgroud)
现在我想将光标放在用户变量上并通过选择"快捷方式"键将其初始化为内联,Intellij将完成上面的语句,如下所示.
List<User> users = userService.findAllUsers()//This method returns List<User> objects
Run Code Online (Sandbox Code Playgroud)
这怎么可能?我是否需要为keymap添加自定义快捷方式,或者是否已在Eclipse中提供了一个?最后,我想了解Mac OSX的快捷方式(如果有的话).
这是我的区域控制器,当我尝试获取数据后保存我得到错误,即使我尝试获取对象形式getDistrict(长id)同样的罢工请建议一些方式,我是非常新的春天环境
package com.gad.services;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.gad.repositories.DistrictMasterRepositories;
import com.gad.rmodels.Districtmaster;
import com.gad.rmodels.Statemaster;
@Service
public class DistricMasterServices {
@Autowired
DistrictMasterRepositories districtMasterRepositories;
@Autowired
StateMasterServices stateMasterServices;
List<Districtmaster> districtmaster;
public Iterable<Districtmaster> savenewdistrict(Long id,Districtmaster districtmaster_rec){
System.out.println(id);
Statemaster statemaster=null;
statemaster = stateMasterServices.getStateById(id);
System.out.println("savenewdistrict");
districtmaster_rec.setStatemaster(statemaster);
districtMasterRepositories.save(districtmaster_rec);
Iterable<Districtmaster>districtmaster2 = districtMasterRepositories.findAll();
return districtmaster2;
}
public Districtmaster getDistrict(Long id){
Districtmaster districtmaster = districtMasterRepositories.findOne(id);
return districtmaster;
}
}
Run Code Online (Sandbox Code Playgroud)
状态的模型类
package com.gad.rmodels;
import static javax.persistence.GenerationType.SEQUENCE;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue; …Run Code Online (Sandbox Code Playgroud) 我正在发送一个JsonObject使用网络服务。接收调用的方法有一个模型对象的方法参数,用于JsonObject传递相应的 输入。在 JsonObject成功得到转换成模型对象,但我没能测试我的一些响应从模型对象。
例如:如果输入 JSON 中缺少任何必填字段,或者如果输入 JSON 中的任何字段设置为null,那么在这两种情况下,模型对象字段都将是null。
我无法检测null是因为字段丢失还是字段设置为null.
有人可以建议我一个解决方案吗?
我最后的出路是,我将接收方法参数输入String而不是我的模型对象,然后使用条件检查,检查输入字符串并相应地获取我的响应。但是我的 JSON 输入对象非常大,我希望有比这更好的方法。
这是一个 Spring Boot 项目。
代码片段:
JSON Object being sent
{"orgType":null, "orgLocation": "Geneva" , //other fields}
@RequestMapping(value="/addOrganizations", method= RequestMethod.POST)
public ResponseEntity addOrganization(@RequestBody Organization organization){
// code goes here
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试
{"orgType":null, "orgLocation": "Geneva" , //other fields}
Run Code Online (Sandbox Code Playgroud)
或者:
{"orgLocation": "Geneva" , //other fields}
Run Code Online (Sandbox Code Playgroud)
并在addOrganization()方法内部使用调试器进行检查,则值null在两种情况下都是如此。
模型类:
public class Organization{
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private …Run Code Online (Sandbox Code Playgroud) 我试图将相同类型的多个对象转换为ListJava中的对象.例如,我的json将是:
{
"Example": [
{
"foo": "a1",
"bar": "b1",
"fubar": "c1"
},
{
"foo": "a2",
"bar": "b2",
"fubar": "c2"
},
{
"foo": "a3",
"bar": "b3",
"fubar": "c3"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我有一节课:
public class Example {
private String foo;
private String bar;
private String fubar;
public Example(){};
public void setFoo(String f){
foo = f;
}
public void setBar(String b){
bar = b;
}
public void setFubar(String f){
fubar = f;
}
...
}
Run Code Online (Sandbox Code Playgroud)
我希望能够将我得到的json字符串转换为Example对象列表.我想做这样的事情:
JSONParser parser = …Run Code Online (Sandbox Code Playgroud) 我试图根据来自父级的信息有条件地序列化子bean。
public class Parent {
private boolean isSecure;
private Child child;
}
public class Child {
String someValue;
}
Run Code Online (Sandbox Code Playgroud)
基本上,如果the parent.isSecure()为true,那么我想someValue比if parent.isSecure()为false 进行序列化。
我的实际类比这个简单的示例要复杂得多,所以我真的不想为此创建一个完整的自定义序列化程序Parent,除非需要向我展示如何Parent在不使用该序列化自定义序列化程序的情况下利用标准序列化,否则我将需要对其进行单独维护。必须遍历所有属性并处理JSON批注,视图等。如果可以,那可能行得通,因为我可以根据来设置上下文属性isSecure()。
我不介意为孩子编写自定义序列化程序,但是我不知道如何从父级检查值。
我考虑过使用“安全”视图和“不安全”视图,我可以在整个序列化过程中指定该视图,但随后我将不得不遍历并注释父类的许多属性,以使其同时处于“安全”状态和“不安全”视图(DEFAULT_VIEW_INCLUSION由于许多我不想序列化的属性,我已经关闭了该选项)。
我尝试generator.getCurrentValue()在自定义的Child序列化程序中进行访问,但是它始终为null,因此不确定该如何工作。
我已经考虑过为编写自定义序列化程序isSecure,并在其中设置上下文属性,但是如何确定在为孩子定制自定义序列化程序之前将其调用?(尽管我承认我不确定上下文属性是否真的像我假设的那样工作。)
有任何想法吗?
我们最近从 Spring Boot 2.1.9 升级到 2.2.1,这导致我们的测试失败。调查导致该java.time.Duration类型现在默认以不同方式序列化。"PT15M"我们现在得到 JSON 消息中的字符串,而不是"900.0". POJO 定义看起来像这样
@JsonProperty(required = true, value = "duration")
@NotNull
private final Duration duration;
Run Code Online (Sandbox Code Playgroud)
现在的问题是,是否有一些配置属性可以用来获取“旧”行为。我知道我们也可以添加注释
@JsonFormat(shape = JsonFormat.Shape.STRING)
Run Code Online (Sandbox Code Playgroud)
但我更喜欢通过配置来获得它的方法。
我在 JSON 反序列化并将其映射到枚举时遇到问题。我从类似于这两个示例的外部 API 获取 JSON:
{
"someValue": null
}
Run Code Online (Sandbox Code Playgroud)
{
"someValue": "exists"
}
Run Code Online (Sandbox Code Playgroud)
我想将空值映射到某个默认枚举值。
模型对象
SomeEnum someValue;
Run Code Online (Sandbox Code Playgroud)
和枚举类
public enum SomeEnum {
@JsonProperty("exists") EXISTS,
NONE;
}
Run Code Online (Sandbox Code Playgroud)
对于存在,值模型类包含正确的枚举,但如果我null从 API获取,它仍然null在模型中。
我尝试创建一些由 注释的方法@JsonCreator,创建自己的枚举反序列化器,使用@JsonEnumDefaultValue但这些解决方案都不适合我。有谁知道,如何将空值反序列化为某个默认枚举?
使用Eclipse时,我可以使用JAX-WS批注(例如@WebService),而无需包含任何外部依赖项,但是我不能对JAX-RS批注(例如@Path)进行相同的操作。我看了一下这个答案,我知道这javax.ws.rs不是JDK的一部分。为什么JAX-WS是JDK的一部分而JAX-RS不是呢?其次,如果我在GlassFish或WildFly服务器上部署带有JAX-WS注释的应用程序,该服务器是否使用众所周知的WebService堆栈来运行该应用程序(例如Metro)或它自己的实现?
我正在使用 Jackson 将 JSON 写入文本文件,JSON 表示从抽象类继承的 2 个类,但无论是否使用了两个类或其中一个/或类,都会发生错误。JSON 似乎写入正确,但在阅读时,我收到以下错误:
Missing type id when trying to resolve subtype of [simple type, class model.BaseContact]: missing type id property 'type'
at [Source: (File); line: 52, column: 1]
json as follows:
{
"allContacts" : [ {
"type" : "personal",
"addressCity" : "Hamilton",
"addressNum" : "199",
"addressPOBox" : null,
"addressPostCode" : null,
"addressStreet" : "River Rd",
"addressSuburb" : null,
"email" : null,
"latitude" : null,
"longitude" : null,
"name" : "silly simon",
"notes" : null, …Run Code Online (Sandbox Code Playgroud) 我正在使用表单验证实现示例Spring MVC表单。我有一个复杂的类型Address作为Student表单bean的bean属性。并且我@NotEmpty为Addressbean属性添加了表单验证。但是,UI中并未反映出同样的情况。但是表单验证适用于其他原始类型的Student表单bean。
所以,验证完全适用于Student表单bean而不是嵌套复杂类型,如Address内Student的form bean。
我正在尝试了解原因和解决方法。
春季版本4.0+。休眠验证器API:5.2.4
Student POJO:
package com.xyz.form.beans;
import java.util.Date;
import java.util.List;
import javax.validation.constraints.Past;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.NotEmpty;
import com.xyz.validators.DateNotEmpty;
import com.xyz.validators.ListNotEmpty;
public class Student {
@Size(min = 2, max = 30)
private String firstName;
@Size(min = 2, max = 30)
private String lastName;
@NotEmpty
private String gender;
@DateNotEmpty
@Past
private Date DOB;
private String email;
private String mobileNumber;
@ListNotEmpty
private List<String> …Run Code Online (Sandbox Code Playgroud) 我的项目是在春天boot 1.5.6.release。
现在迁移到 version 之后2.1.3。发布,运行时显示以下错误:
java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.([Ljava/lang/Object;)V 在 org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:157) 在 org.springframework。 cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:98) 在 org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:64) 在 org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.doInvokeListener(Simple.java:64) 172) 在 org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) 在 org.springframework.context.event.SimpleApplicationEventMulticaster。org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:75) 处的多播事件(SimpleApplicationEventMulticaster.java:139) .springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) 在 org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:347) 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:306) 在org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) 在 org.netlink.workboard.application。WorkboardApiApplication.main(WorkboardApiApplication.java:25)
POM文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>workboard-api</groupId>
<artifactId>workboard-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>workboard-api</name>
<description>Demo project for Spring Boot</description>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath /> <!-- lookup parent …Run Code Online (Sandbox Code Playgroud) java ×9
jackson ×5
json ×5
spring-boot ×4
spring ×3
annotations ×1
forms ×1
hibernate ×1
hotkeys ×1
java-ee ×1
jax-rs ×1
jax-ws ×1
maven-2 ×1
oval ×1
parsing ×1
recursion ×1
spring-mvc ×1
svenson ×1
validation ×1
web-services ×1