我使用最新版本的Spring Boot通过Restful Web Service读取示例JSON ...
这是我的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>myservice</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.2.RELEASE</version>
</parent>
<properties>
<java.version>1.7</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-webmvc</artifactId>
</dependency>
<dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>https://repo.spring.io/libs-release</url>
</repository>
<repository>
<id>org.jboss.repository.releases</id>
<name>JBoss Maven Release Repository</name>
<url>https://repository.jboss.org/nexus/content/repositories/releases</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
</project>
Run Code Online (Sandbox Code Playgroud)
这是我的网络服务代码:
import org.springframework.web.bind.annotation.RequestBody; …
Run Code Online (Sandbox Code Playgroud) 我目前在MacBook Pro上运行OS X Yosemite(10.10.2)...默认情况下,Apple在Yosemite上运行Python 2.7.6.
刚刚下载并运行了Python 3的这个安装程序: python-3.4.3-macosx10.6.pkg
当我打开终端并输入时python
,会出现这种情况:
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Run Code Online (Sandbox Code Playgroud)
问题(S):
如何在Oracle SQL Developer中增加缓冲区大小以查看所有记录(默认情况下似乎设置了某个限制)?任何屏幕截图和/或提示都将非常有用.
如何使用Jackson将Map转换为有效的JSON?
我是通过Spring Boot REST Post方法使用谷歌的GSON做的...
这是RESTful Web服务:
import java.util.Map;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.google.gson.Gson;
@RestController
@RequestMapping("/myservice")
public class ValidationService {
@RequestMapping(value="/validate", method = RequestMethod.POST)
public void validate(@RequestBody Map<String, Object> payload) throws Exception {
Gson gson = new Gson();
String json = gson.toJson(payload);
System.out.println(json);
}
}
Run Code Online (Sandbox Code Playgroud)
所以,当我使用它调用它时:
curl -H "Accept: application/json" -H "Content-type: application/json" \
-X POST -d '{"name":"value"}' http://localhost:8080/myservice/validate
Run Code Online (Sandbox Code Playgroud)
收到以下stdout(这正是我想要的):
{"name":"value"}
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来使用杰克逊而不是谷歌的Gson和/或我完全以错误的方式解决这个问题?
我试图使用Java Reflection获取和调用驻留在不同类中的受保护方法以及不同的包.
包含受保护方法的类:
package com.myapp;
public class MyServiceImpl {
protected List<String> retrieveItems(String status) {
// Implementation
}
}
Run Code Online (Sandbox Code Playgroud)
通话课程:
package xxx.myapp.tests;
import com.myapp.MyServiceImpl;
public class MyTestCase {
List<String> items;
public void setUp() throws Exception {
MyServiceImpl service = new MyServiceImpl();
Class clazz = service.getClass();
// Fails at the next line:
Method retrieveItems = clazz.getDeclaredMethod("retrieveItems");
// How to invoke the method and return List<String> items?
// tried this but it fails?
retrieveItems.invoke(clazz, "S");
}
}
Run Code Online (Sandbox Code Playgroud)
编译器抛出此异常:
java.lang.NoSuchMethodException: com.myapp.MyServiceImpl.retrieveItems()
Run Code Online (Sandbox Code Playgroud) 我正在寻找一个用Java或Python编写的规则引擎,它支持以下功能:
已经排除了Drools(非常笨重,对非技术用户不友好).
到目前为止候选人是:
阅读Easy Rules不支持前向和后向链接,以及广度优先和深度优先搜索策略.
它只执行一次所有规则.
任何人都可以建议一个基于开源的规则引擎,用Java或Python编写?
感谢您抽时间阅读.
我试图使用Spring Secruity的OAuth API从外部发布的API获取访问令牌.
这个curl命令有效(它的内容就是我获取访问令牌所需的全部内容):
curl -X POST \
https://api.app.com/v1/oauth/token \
-H 'content-type: application/x-www-form-urlencoded' \
-d'grant_type=client_credentials&client_id=bcfrtew123&client_secret=Y67493012'
Run Code Online (Sandbox Code Playgroud)
运行此curl命令后,能够从外部服务获取访问令牌.
使用Spring Security OAuth API时:
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
设置我的SpringMVC Controller的方法如下:
@RequestMapping(value = "/getAccessToken", method = RequestMethod.POST, consumes="application/x-www-form-urlencoded")
public OAuth2AccessToken getAccessToken(@RequestParam(value="client_id", required=true) String clientId, @RequestParam(value="client_secret", required=true) String clientSecret) throws Exception {
String tokenUri = "https://api.app.com/v1/oauth/token";
ResourceOwnerPasswordResourceDetails resourceDetails = new ResourceOwnerPasswordResourceDetails();
resourceDetails.setAccessTokenUri(tokenUri);
resourceDetails.setClientId(clientId);
resourceDetails.setClientSecret(clientSecret);
resourceDetails.setGrantType("client_credentials");
resourceDetails.setScope(Arrays.asList("read", "write"));
DefaultOAuth2ClientContext clientContext = new DefaultOAuth2ClientContext();
oauth2RestTemplate = new OAuth2RestTemplate(resourceDetails, clientContext);
OAuth2AccessToken token = oauth2RestTemplate.getAccessToken();
return token;
}
Run Code Online (Sandbox Code Playgroud)
当我从本地tomcat实例调用getAccessToken调用时: …
有一个基于Spring Boot(1.5.4.RELEASE)的微服务,我将jar部署到AWS EC实例(Linux环境).现在,我还部署了一个外部log4j.properties文件,所以我必须像这样启动微服务:
java -jar myapp.jar -Dlogging.config=/path/to/log4j.properties
Run Code Online (Sandbox Code Playgroud)
如何将此Spring Boot微服务配置为Linux服务,我可以使用这些标志启动和停止它:
sudo service myapp start | stop | status | restart
Run Code Online (Sandbox Code Playgroud)
非常感谢你.
我安装了Scala IDE - Play 2插件(来自http://download.scala-ide.org/play2/nightly_3.0-M_juno_2.10-M/site/),而路径编辑器显示正确的语法高亮显示, Scala的模板没有.此外,它还不允许我在Eclipse的首选项 - >播放 - >模板 - 语法着色中"启用"语法突出显示选项.
因此,在main.scala.html和index.scala.html中没有突出显示Scala语法
我还使用http://download.scala-ide.org/nightly-scala-ide-juno-210x进行Eclipse Juno.
-詹姆士
用鼠标右键单击上面的图像,在新的浏览器选项卡中打开,以全分辨率查看图像.
我是Spring Boot和JPA的新手......
假设我有两个实体映射到两个表,这两个表在数据库中连接.
学生 - 1 ------ < - 课程
另外,假设已经创建并填充了数据库.
这表明一个学生有很多课程......
我的学生实体:
@Entity
public class Student {
@OneToMany(mappedBy="student")
private List<Courses> courses;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "Student_Id")
private long studentId;
@Column(name = "Student_Name")
private String studentName;
protected Student() { }
// Getters & Setters
}
Run Code Online (Sandbox Code Playgroud)
我的课程实体:
@Entity
public class Course {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "Course_Id")
private long courseId;
@Id
@Column(name = "Student_Id")
private long studentId;
@ManyToOne
@PrimaryKeyJoinColumn(name="Student_Id", referencedColumnName="Student_Id")
private Student student;
@Column(name = "Course_Name")
private …
Run Code Online (Sandbox Code Playgroud) java ×7
spring-boot ×3
json ×2
python ×2
spring ×2
spring-mvc ×2
curl ×1
eclipse ×1
gson ×1
hibernate ×1
hql ×1
jackson ×1
jpa ×1
junit ×1
linux ×1
log4j ×1
oauth ×1
oracle ×1
oracle11g ×1
osx-yosemite ×1
protected ×1
python-2.7 ×1
python-3.x ×1
reflection ×1
rest ×1
rule-engine ×1
scala ×1
scala-ide ×1
sql ×1