我有一个非常标准的Spring Boot应用程序(application.properties属性文件位于标准/src/main/resources文件夹中),我将其作为"胖JAR"部署在AWS Elastic Beanstalk上.它工作得很好,但是服务器上的图像上传存在问题.经过一些调查后,似乎需要调整NGINX配置(增加到client_max_body_size可以接受上传的内容10MB),因此我添加了一个带有以下内容的文件.ebextensions夹/src/main/resources(取自此答案): -
files:
"/etc/nginx/conf.d/proxy.conf":
mode: "000755"
owner: root
group: root
content: |
client_max_body_size 20M;
Run Code Online (Sandbox Code Playgroud)
但是,当我运行mvn我的构建时,它不会.ebextensions在根文件夹中创建,我想知道什么是最佳解决方案.我的pom.xml文件很小,目前包含以下内容:
...
<packaging>jar</packaging>
....
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.6.RELEASE</version>
</dependency>
</dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)
提前致谢!
@Lorena当我<resources> ...向我插入XML pom.xml然后启动服务器时,它崩溃了以下内容: -
2017-03-20 21:40:29.504 WARN 10784 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: …Run Code Online (Sandbox Code Playgroud) spring-boot amazon-elastic-beanstalk spring-boot-maven-plugin
我正在构建一个2层的应用程序: -
1.原生Android应用程序 - 包含通过Facebook + Google登录以减少痛苦登记的能力.
2.使用Spring Boot的Java Server - 典型的MVC端点,例如REST api + UI管理屏幕.
Facebook(FacebookSdk)和Google(GoogleApiClient)登录部分正在使用以下Android依赖项进行工作和测试: -
dependencies {
compile 'com.facebook.android:facebook-android-sdk:4.6.0'
compile 'com.google.android.gms:play-services-auth:9.0.0'
....
}
Run Code Online (Sandbox Code Playgroud)
API我们有: -
/api/signin- 当用户使用Facebook + Google成功登录并在users数据库表中创建条目时调用.
还有许多其他API端点,例如优惠
/api/offers/<user_id>- 向已注册的用户返回优惠.
我不确定最佳实践方式: -
android应用程序如何对/ api/signin REST端点进行API调用(即哪些标头等可以发送到我认为是没有安全性的端点,因为未注册的用户将会遇到此问题).另外,在usersdb表中可以保存哪些字段?
Android应用程序如何调用例如/ api/offers /已经注册的用户?即当Android应用程序传递时令牌等等?
Spring安全性保护这些端点的最佳实践方法.
假设OAuth 2是要走的路,但任何建议/指针都将受到最多的赞赏.
android spring-security android-facebook spring-boot android-security
我一直在为PostgreSQL中的这个问题摸不着头脑.我有一个test有两列的表: - id和content.例如
create table test (id integer,
content varchar(1024));
insert into test (id, content) values
(1, 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.'),
(2, 'Lorem Ipsum has been the industrys standard dummy text '),
(3, 'ever since the 1500s, when an unknown printer took a galley of type and scrambled it to'),
(4, 'make a type specimen book.'),
(5, 'It has survived not only five centuries, but also the …Run Code Online (Sandbox Code Playgroud) 我目前正在创建一个单元自定义JUnit运行器(它将在每个测试方法之前/之后精确调用自定义代码),例如
class MyRunner extends BlockJUnit4ClassRunner {
private MyApi api = new MyApi();
public MyRunner(Class<?> klass) throws InitializationError {
super(klass);
}
// todo
}
Run Code Online (Sandbox Code Playgroud)
不过,我想支持其他选手如MockitoJunitRunner和SpringRunner这样的,而不是重新发明轮子,我想用我的亚军如下内容(使用自定义MyConfig批注指定现有的测试跑步者): -
@RunWith(MyRunner.class)
@MyConfig(testRunner=MockitoJUnitRunner.class)
public class MockitoRunnerTest {
}
Run Code Online (Sandbox Code Playgroud)
... 要么 ...
@RunWith(MyRunner.class)
@MyConfig(testRunner=SpringRunner.class)
public class MockitoRunnerTest {
}
Run Code Online (Sandbox Code Playgroud)
这意味着测试运行器非常轻,即它类似于Junit规则,并在调用它自己的代码后简单地代理另一个现有的Junit运行器.
我的直觉是,这已经得到实施/解决 - 只是遇到了问题.
注意:由于这些问题,我想避免使用规则 - 请参阅每个'@Test'后的'@Rule'和JUnit中每个'@After'之前的应用'@Rule'
我正在努力在PostgreSQL数据库中的JSONB字段上进行聚合.这可能更容易用一个例子解释,所以如果创建并填充一个名为analysis2列(id和analysis)的表,如下所示: -
create table analysis (
id serial primary key,
analysis jsonb
);
insert into analysis
(id, analysis) values
(1, '{"category" : "news", "results" : [1, 2, 3, 4, 5 , 6, 7, 8, 9, 10, 11, 12, 13, 14, null, null]}'),
(2, '{"category" : "news", "results" : [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, null, 26]}'),
(3, '{"category" : "news", "results" : [31, 32, 33, 34, …Run Code Online (Sandbox Code Playgroud) 我正在尝试在运行时读取Java系统属性,基于includes列表进行过滤(此处硬编码但通常通过属性文件注入),最后按键排序并转换为a Map<String, String>.这就是我提出的,但不确定它是否是最优雅的解决方案.
final List<String> includes = Arrays
.asList("java.version", "PID", "os.name", "user.country"); // hard coded here but (usually defined in a properties file)
Map<String, String> systemMap = System.getProperties()
.entrySet().stream()
.filter(s -> includes != null && includes.contains(s.getKey()))
.sorted(Comparator.comparing(
Map.Entry::getKey, Comparator.comparing(e -> (String) e))
)
.collect(Collectors.toMap(
e -> (String) e.getKey(),
e -> (String) e.getValue(),
(e1, e2) -> e2,
LinkedHashMap::new)
);
Run Code Online (Sandbox Code Playgroud)
我很想知道代码是否可以整理.
我搜索了与此相当的Materialize UI的高低(在较轻的MUI CSS中的示例): -
https://www.muicss.com/docs/v1/example-layouts/responsive-side-menu
Run Code Online (Sandbox Code Playgroud)
例如在桌面上看起来像这样(能够通过汉堡图标显示/隐藏菜单): -
但在移动设备上看起来像这样: -
我试图找出一个简单的转换的最优雅的方式int排列(例如{1, 2, 3}),以一个简单的String阵列(例如,{"id", "1", "id", "2", "id", "3"}使用Java 8流串对).
传统上代码如下: -
int[] input = {1, 2, 3};
String[] output = new String[input.length * 2];
int i = 0;
for (int val : input) {
output[i++] = "id";
output[i++] = String.valueOf(val);
}
Run Code Online (Sandbox Code Playgroud)
但假设这可以在Java 8中用1-liner完成.
我已经浏览了 AssertJ 示例(https://github.com/joel-costigliola/assertj-examples/blob/master/assertions-examples/src/test/java/org/assertj/examples/IterableAssertionsExamples.java)但是我找不到以下示例:-
3null例如
List<String> items= Arrays.asList(null, null, null);
assertThat(items).hasSize(3).containsOnlyNulls();
Run Code Online (Sandbox Code Playgroud)
注意 -
containsOnlyNulls不存在,但这基本上是我想要测试的。这可以在 AssertJ 中实现吗?
java-8 ×2
java-stream ×2
postgresql ×2
spring-boot ×2
android ×1
arrays ×1
assertj ×1
java ×1
jsonb ×1
junit-runner ×1
junit4 ×1
lambda ×1
materialize ×1
sql ×1