我正在构建我的第一个 Springboot 2.0 应用程序。我试图将我的 Springboot 应用程序放入一个 docker 容器,将我的 PostgresDB 放入另一个容器中。
我的 Dockerfile
FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD springboot-api-demo-0.1*.jar app.jar
RUN sh -c 'touch /app.jar'
EXPOSE 9443
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/urandom -jar /app.jar" ]
Run Code Online (Sandbox Code Playgroud)
我的 docker-compose.yml 文件
version: "2.1"
services:
springboot-api-demo:
image: "fw/springboot-api-demo"
mem_limit: 1024m
ports:
- "8080:8080"
environment:
- SPRING_PROFILES_ACTIVE=local
- AWS_REGION=local
- ENVIRONMENT=local
- AUTH_ENABLED=false
postgres:
container_name: pgdb
image: postgres:9.6-alpine
environment:
- 'POSTGRES_ROOT_PASSWORD=postgres'
- 'POSTGRES_USER=postgres'
- 'POSTGRES_PASSWORD=postgres'
ports:
- "54321:5432"
Run Code Online (Sandbox Code Playgroud)
我在application.properties 中使用 Springboot JPA …
下面的代码显示空指针异常..
public class MyFragment extends Fragment {
private String[] eArray = getActivity()
.getResources()
.getStringArray(R.array.English);
Run Code Online (Sandbox Code Playgroud)
有什么其他的选择,在stackoverflow中搜索没有给我成功..我也使用FragmentPagerAdapter ..这与此eArray无关..但它包含图像数据.
我之前使用 Java 1.7 运行我的项目,但现在我必须将其升级到版本 1.8。我将它作为替代安装安装在我的 CentOS 上。
Java8 的位置为/opt/jdk1.8.0_25/,当前 Java 的位置为/usr/java/jdk1.7.0_67/。我的系统JAVA_HOME也指向/usr/java/jdk1.7.0_67/.
当我添加新的 SDK 时,我收到此错误:Cannot Save Settings: Please specify a different SDK name。
我应该如何解决这个问题?
在将字符串解析为byte时遇到异常
String Str ="9B7D2C34A366BF890C730641E6CECF6F";
String [] st=Str.split("(?<=\\G.{2})");
byte[]bytes = new byte[st.length];
for (int i = 0; i <st.length; i++) {
bytes[i] = Byte.parseByte(st[i]);
}
Run Code Online (Sandbox Code Playgroud) 我有一个活动,向用户显示内的产品列表HorizontalScrollView。我正在使用Robolectric测试产品列表较长时滚动视图是否显示箭头。
在我的活动中,我这样注册OnGlobalLayoutListener:
ViewTreeObserver vto = productsScrollView.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
productsScrollView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
maxScrollX = productsScrollView.getChildAt(0)
.getMeasuredWidth() - productsScrollView.getMeasuredWidth();
hideShowArrowsAsNeeded();
}
});
Run Code Online (Sandbox Code Playgroud)
当productsScrollView视图层次结构更改时(即,我已经向其中添加了一些子视图),将调用此侦听器。我运行该应用程序,并且一切正常。
问题是我不知道如何测试该hideShowArrowsAsNeeded方法是否能完成工作。在我的Robolectric测试中,我有以下内容:
@Test
public void testThatAHugeNumberOfProductsShowRightArrow() throws Exception {
Product product1 = new Product();
product1.setName("Product1");
Product product2 = new Product();
product2.setName("Product2");
...
ArrayList<Product> productsList = new ArrayList<Product>();
productsList.add(product1);
productsList.add(product2);
...
activity.drawProducts(productsList); // Here I add the views to the scroll view and onGlobalLayout is eventually called, but now …Run Code Online (Sandbox Code Playgroud) 当我想引用构造函数之外的数组元素时,程序会抛出我 NullPointerException (location: function ratio)
private int tabPascal[][];
Pascal(int n){
int tabPascal [][]= new int[n+1][];
for(int i = 0; i <= n; i++){
tabPascal[i] = new int[i+1];
}
for(int i = 0; i < tabPascal.length; i++){
for(int j = 0; j<tabPascal[i].length; j++){
tabPascal[i][j] = binomial(i,j);
System.out.print(tabPascal[i][j] + " ");
}
System.out.println();
}
}
Run Code Online (Sandbox Code Playgroud)
...
public int ratio(int n, int k){
return tabPascal[n][k];
}
Run Code Online (Sandbox Code Playgroud) java ×4
android ×2
exception ×2
asynchronous ×1
docker ×1
postgresql ×1
robolectric ×1
spring-boot ×1