小编DK1*_*990的帖子

使用外部属性文件配置的表名

我构建了一个访问数据库并从中提取数据的 Spring-Boot 应用程序。一切正常,但我想从外部 .properties 文件配置表名。

喜欢:

@Entity
@Table(name = "${fleet.table.name}")
public class Fleet {
...
}
Run Code Online (Sandbox Code Playgroud)

我试图找到一些东西,但我没有。

您可以使用@Value("...")注释访问外部属性。

所以我的问题是:有什么办法可以配置表名?或者我可以更改/拦截休眠发送的查询吗?

解决方案:

好的,hibernate 5 与PhysicalNamingStrategy. 所以我创建了自己的PhysicalNamingStrategy.

@Configuration 
public class TableNameConfig{

    @Value("${fleet.table.name}")
    private String fleetTableName;

    @Value("${visits.table.name}")
    private String visitsTableName;

    @Value("${route.table.name}")
    private String routeTableName;

    @Bean
    public PhysicalNamingStrategyStandardImpl physicalNamingStrategyStandard(){
        return new PhysicalNamingImpl();
    }

class PhysicalNamingImpl extends PhysicalNamingStrategyStandardImpl {

    @Override
    public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment context) {
        switch (name.getText()) {
            case "Fleet":
                return new Identifier(fleetTableName, name.isQuoted());
            case "Visits":
                return new …
Run Code Online (Sandbox Code Playgroud)

spring spring-data

12
推荐指数
1
解决办法
6160
查看次数

maven-surefire-plugin dummy:dummy.jar:1.0 缺失

我无法成功构建我的构建,因为该org.apache.maven.surefire:surefire-junit4:jar:2.18.1插件缺少 dummy.jar。

我的 Maven 从我的自定义存储库中下载了所有内容。所以不存在网络问题。此外,此问题出现在maven-surefire-plugin.

希望有人可以帮助我。我只是不明白问题出在哪里。

错误:

[INFO] ---------------------------------------------------------------------    ---
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.465 s
[INFO] Finished at: 2017-05-11T11:20:13+02:00
[INFO] Final Memory: 24M/262M
[INFO] ---------------------------------------------------------------------    ---
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-    plugin:2.18.1:test (default-test) on project qds-mobile-selenium-tests:             Unable to generate classpath:     org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException: 
Missing:
[ERROR] ----------
[ERROR] 1) org.apache.maven.surefire:surefire-junit4:jar:2.18.1
[ERROR] 
[ERROR]   Try downloading the file manually from the project website.
[ERROR] 
[ERROR]   Then, install it using the command: 
[ERROR]       mvn install:install-file -DgroupId=org.apache.maven.surefire …
Run Code Online (Sandbox Code Playgroud)

java apache jar maven maven-surefire-plugin

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

授予 EC2 实例访问 S3 存储桶的权限

我想授予我的 ec2 实例访问 s3 存储桶的权限。

在这个 ec2 实例上,启动了一个包含我的应用程序的容器。现在我没有获得 s3 存储桶的许可。

这是我的存储桶策略

{
"Version": "2012-10-17",
"Id": "Policy1462808223348",
"Statement": [
    {
        "Sid": "Stmt1462808220978",
        "Effect": "Allow",
        "Principal": {
            "AWS": "arn:aws:iam::714656454815:role/ecsInstanceRole"
        },
        "Action": "s3:GetObject",
        "Resource": "arn:aws:s3:::bucket-name/*",
        "Condition": {
            "IpAddress": {
                "aws:SourceIp": "private-ip/32"
            }
        }
    }
]
}
Run Code Online (Sandbox Code Playgroud)

但是直到我授予存储桶每个人都可以访问它的权限后,它才起作用。

我尝试从 ec2 实例内部卷曲 s3 存储桶中的文件,但这也不起作用。

amazon-s3 amazon-ec2 amazon-web-services amazon-policy

2
推荐指数
1
解决办法
4859
查看次数

如何模拟DriverManager.getConnection?

如何模拟DriverManager.getConnection()方法?

我想测试我的方法setUpConnectiontoDB()

我尝试使用PowerMock,easyMock和Mokito本身.我没有找到任何有用的东西.

我的代码:

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class MysqlDAO implements DAO {
    private final Properties properties = new Properties();

    public MysqlDAO(String configPath) {
        loadProperties(configPath);
    }

    private Properties loadProperties(String configPath) {
        try {
            properties.load(new FileInputStream(configPath));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return this.properties;
    }

    @Override
    public Connection setUpConnectionToDB() {
        try {
            Class.forName("com.mysql.jdbc.Driver");

            return DriverManager.getConnection(
                    properties.getProperty("url"),
                    properties.getProperty("user"),
                    properties.getProperty("passwd"));

        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

java jdbc mocking mockito

0
推荐指数
1
解决办法
1307
查看次数