小编Kir*_*ill的帖子

LayoutInflater的Factory和Factory2之间有什么区别

有两个公共接口:
LayoutInflater.FactoryLayoutInflater.Factory2在Android SDK中,但正式文件不能说这个接口,甚至一些有益的LayoutInflater资料.

从我已经了解的情况来看,如果Factory2已经设置,那么它将被使用,Factory否则:

View view;
if (mFactory2 != null) {
    view = mFactory2.onCreateView(parent, name, context, attrs);
} else if (mFactory != null) {
    view = mFactory.onCreateView(name, context, attrs);
} else {
    view = null;
}
Run Code Online (Sandbox Code Playgroud)

setFactory2() 也有非常简洁的文件:

/**
 * Like {@link #setFactory}, but allows you to set a {@link Factory2}
 * interface.
 */
public void setFactory2(Factory2 factory) {
Run Code Online (Sandbox Code Playgroud)


我应该使用哪家工厂如果我想将自定义工厂设置为LayoutInflater?它们的区别是什么?

java android layout-inflater

9
推荐指数
1
解决办法
602
查看次数

使用动态名称管理单个 Pod 的 RBAC 角色

我需要使用 RBAC 授予对一个部署和此部署的所有 pod 的访问权限。我已经成功地配置RoleRoleBindingdeploymet,这是工作的罚款:

---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  namespace: <my-namespace>
  name: <deployment>-manager-role
rules:
  - apiGroups: ["", "extensions", "apps"]
    resources: ["deployments"]
    resourceNames: ["<deployment>"]
    verbs: ["get", "list", "watch", "update", "patch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: <deployment>-manager-binding
  namespace: <my-namespace>
subjects:
  - kind: User
    name: <username>
    apiGroup: ""
roleRef:
  kind: Role
  name: <deployment>-manager-role
  apiGroup: ""
Run Code Online (Sandbox Code Playgroud)

使用此角色用户可以访问、更新和修补部署。此部署创建具有动态名称(如<deployment>-5594cbfcf4-v4xx8)的pod 。我试图允许此用户使用部署名称和使用部署名称 + 通配符字符访问这些 pod(获取、列出、监视、读取日志、执行、删除)*

---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  namespace: <my-namespace>
  name: …
Run Code Online (Sandbox Code Playgroud)

roles rbac kubernetes kubernetes-deployment kubernetes-pod

9
推荐指数
1
解决办法
3131
查看次数

错误:列的类型为 json,但表达式的类型为 Hibernate 中不同的字符

我需要使用 spring 数据 jpa 在 postgres 中将实体类的两列映射为 json。在阅读了多个 stackoverflow 帖子和 baeldung 帖子后,

如何使用 JPA 将映射 JSON 列映射到 Java 对象

https://www.baeldung.com/hibernate-persist-json-object

我做了如下配置。但是,我面临错误“错误:列“标题”的类型为 json,但表达式的类型为不同的字符

请提供一些解决此问题的指针。

我有一个实体类如下

@Entity
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class Task {
    @Id
    @GeneratedValue(strategy = IDENTITY)
    private Integer id;
    
    private String url;
    private String httpMethod;

    @Convert(converter = HashMapConverter.class)
    @Column(columnDefinition = "json")
    private Map<String, String> headers;

    @Convert(converter = HashMapConverter.class)
    @Column(columnDefinition = "json")
    private Map<String, String> urlVariables;
}
Run Code Online (Sandbox Code Playgroud)

我创建了一个测试类来测试实体是否持久化。在运行这个 junit 时,下面的测试用例失败,错误如下

在此处输入图片说明

@SpringBootTest
class TaskRepositoryTest {

    private static Task randomTask …
Run Code Online (Sandbox Code Playgroud)

postgresql json liquibase spring-data-jpa spring-boot

9
推荐指数
4
解决办法
3721
查看次数

使用 testcontainers 复制资源时更改文件的所有者

我在 Java 测试中使用 testcontainers。要在容器中配置应用程序,我需要放置并安装配置文件:一些文件是静态的,因此我withClassPathResourceMapping在创建新容器时使用安装它们:

container.withClassPathResourceMapping(
  "/path/to/res",
  "/etc/app/config.name",
  BindMode.READ_ONLY
)
Run Code Online (Sandbox Code Playgroud)

其他文件是动态生成的,可以被容器中的应用程序覆盖,因此我copyFileToContainer在容器启动后使用将内容复制到容器:

container.copyFileToContainer(
 Transferable.of(bin /* byte[] */),
 "/var/app/resource.name"
)
Run Code Online (Sandbox Code Playgroud)

app:app该应用程序作为在Dockerfile.

我这里有两个类似的问题:

  1. withClassPathResourceMapping如果未找到,操作将创建丢失的目录,例如用于"/etc/app/config.name"创建"/etc/app/目录的类路径映射。但它以用户身份创建这些目录root:root,因此应用程序稍后无法在此目录中创建新文件
  2. 使用复制到容器中的文件copyFileToContainer不是只读的,可以由应用程序修改。但copyFileToContainer以用户身份创建文件root:root,因此应用程序无法写入这些文件。

我尝试chown -R /path在容器启动后执行,但此命令失败,因为执行用户不是root.

在测试容器中设置所有者和权限的正确方法是什么?

java unit-testing docker testcontainers

9
推荐指数
0
解决办法
1112
查看次数

如何复制调试资产以进行单元测试

我有一个android库gradle项目.我需要将一些文件复制到资源文件夹以进行robolectric单元测试.

要做到这一点,我已经定义了一个复制任务:

task copyDebugAssets(type: Copy)  {
    from "${projectDir}/somewhere"
    into "${buildDir}/intermediates/bundles/debug/assets"
}
Run Code Online (Sandbox Code Playgroud)

但我不能将此任务添加为processDebugResources任务的依赖项:

processDebugResources.dependsOn copyDebugAssets
Run Code Online (Sandbox Code Playgroud)

因为这个错误:

无法为com.android.build.gradle.LibraryExtension类型的对象获取未知属性'processDebugResources'.

现在我必须在单元测试之前手动执行此任务:

./gradlew clean copyDebugAssets test
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

android unit-testing gradle android-library android-gradle-plugin

8
推荐指数
1
解决办法
635
查看次数

Heroku使用端口参数运行Docker镜像

当我将现有的Docker镜像推送到Heroku时,Heroku提供了一个$PORT环境变量.如何将此属性传递给Heroku运行实例?

localhost这样的工作:

docker pull swaggerapi/swagger-ui
docker run -p 80:8080 swaggerapi/swagger-ui
Run Code Online (Sandbox Code Playgroud)

在Heroku我应该这样做:

docker run -p $PORT:8080 swaggerapi/swagger-ui
Run Code Online (Sandbox Code Playgroud)

这样的事情可能吗?

heroku docker dockerfile

8
推荐指数
1
解决办法
468
查看次数

BroadcastReceiver不接收广播

我的BroadcastReceiver没有收到任何东西.很可能是我的设置错了,因为我无法在此找到任何好的例子.我需要我的接收器在我的MainActivity中接收一些东西,并更改一个视图.我在Android项目中有几乎相同的代码,并且它在这里工作,但是在Xamarin中,BroadcastReceivers似乎实现了一点点不同(在Android中,我可以使新的BroadcastReceiver几乎像一个对象,但在Xamarin或C#中,似乎我必须创建自己的类,因此没有相同的可能性直接引用视图).如果我让这个工作,我也会为每个人发布一个完整的工作示例.

以下是我尝试设置它的方法:

[Activity(Label = "GetLocation.Droid", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
    Button button;
    protected override void OnCreate(Bundle bundle)
    {
        // ... various OnCreate() code

        LocationBroadcastReciever lbr = new LocationBroadcastReciever();
        RegisterReceiver(lbr, new IntentFilter("test"));

    }

    public void SetButtonText(string text)
    {
        button.Text = text;
    }
}

[BroadcastReceiver]
public class LocationBroadcastReciever : BroadcastReceiver
{
    public override void OnReceive(Context context, Intent intent)
    {
        /* My program never get this far, so I have not been able
           to confirm if …
Run Code Online (Sandbox Code Playgroud)

c# android broadcastreceiver xamarin

7
推荐指数
1
解决办法
6451
查看次数

无法从配置文件配置附加系统属性

我有Maven故障安全插件的构建配置,其中包括systemPropertyVariables

<build>
  <plugins>
    <plugin>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.19.1</version>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <systemPropertyVariables>
            <buildDirectory>${project.build.directory}</buildDirectory>
          </systemPropertyVariables>
        </configuration>
      </plugin>
  </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

我也有一个配置文件,可以通过pluginManagement以下方式将少量属性附加到同一插件:

<profile>
  <id>test</id>
  <activation>
    <property>
      <name>test.host</name>
    </property>
  </activation>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-failsafe-plugin</artifactId>
          <configuration>
            <systemPropertyVariables>
              <TEST_HOST>test.host</TEST_HOST>
            </systemPropertyVariables>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</profile>
Run Code Online (Sandbox Code Playgroud)

但是我无法从此配置文件中读取属性。如果我systemPropertyVariables在构建插件配置部分中删除并保留配置文件的pluginManagement配置,则可以正常工作。看来,我需要合并这些属性一起使用时,所以我尝试添加combine.children="append"combine.self="append"configuration插件的,但它并没有帮助。

更新: 我已经找到了导致此问题的原因:我没有提到我的父pom包括这个,而父pom.xml有以下几行:

<build>
  <plugins>
    <plugin>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.19.1</version>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <systemPropertyVariables>
            <buildDirectory>${project.build.directory}</buildDirectory>
          </systemPropertyVariables> …
Run Code Online (Sandbox Code Playgroud)

pom.xml maven maven-profiles

6
推荐指数
1
解决办法
179
查看次数

AppCompat Fragment生命周期发生了变化

在更新到新的appcompat库之后,com.android.support:appcompat-v7:25.1.0我在替换事务中的片段时获得了新的片段生命周期.

例如我有两个片段FrFirstFrSecond用日志中onStartonStop,并用我第一替换第一与第二,然后第二:FrFirst -> FrSecond -> FrFirst.

getActivity().getSupportFragmentManager()
    .beginTransaction()
    .replace(R.id.content, new FrSecond())
    .commit();
Run Code Online (Sandbox Code Playgroud)

在以前的appcompat版本中,我可以读取此日志:

FrFirst:导航到第二个
FrFirst:停止
FrSecond:开始

FrSecond:导航到第一个
FrSecond:停止
FrFirst:开始

在25.1.0中这个日志:

FrFirst:导航到第二个
FrSecond:开始
FrFirst:停止

FrSecond:导航到第一个
FrFirst:开始
FrSecond:停止

所以现在onStart呈现onStop当前之前调用的片段.

为什么方法顺序改变了,它是支持库中的错误吗?

android android-appcompat android-lifecycle android-fragments fragment-lifecycle

5
推荐指数
1
解决办法
680
查看次数

JDK-13 不支持surefire插件的类文件主要版本

我正在尝试使用 Java-13 和 Maven 创建 Java 模块项目。我的pom.xml是:

<?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>wtf.g4s8</groupId>
  <artifactId>oot</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <properties>
    <junit-platform.version>5.3.1</junit-platform.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <jdk.version>13</jdk.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest</artifactId>
      <version>2.1</version>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>${junit-platform.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <version>${junit-platform.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <target>${jdk.version}</target>
          <source>${jdk.version}</source>
          <release>${jdk.version}</release>
          <useIncrementalCompilation>false</useIncrementalCompilation>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M3</version>
      </plugin>
    </plugins>
  </build>
</project>
Run Code Online (Sandbox Code Playgroud)

版本:

$ mvn help:system | grep -i jdk
sun.boot.library.path=/opt/jdk-13.0.1/lib
jdk.debug=release
java.home=/opt/jdk-13.0.1
java.runtime.name=OpenJDK Runtime Environment …
Run Code Online (Sandbox Code Playgroud)

java maven maven-surefire-plugin java-13

5
推荐指数
2
解决办法
1901
查看次数