小编Ily*_*nov的帖子

@ConfigurationProperties前缀不起作用

.yml文件

cassandra:
    keyspaceApp:junit
solr:
    keyspaceApp:xyz
Run Code Online (Sandbox Code Playgroud)

@Component
@ConfigurationProperties(prefix="cassandra")
public class CassandraClientNew {
   @Value("${keyspaceApp:@null}") private String keyspaceApp;
Run Code Online (Sandbox Code Playgroud)

主方法文件

@EnableAutoConfiguration
@ComponentScan
@PropertySource("application.yml")
public class CommonDataApplication {
    public static void main(String[] args) {
        ConfigurableApplicationContext context = new SpringApplicationBuilder(CommonDataApplication.class)
                .web(false).headless(true).main(CommonDataApplication.class).run(args);
    }
}
Run Code Online (Sandbox Code Playgroud)

测试用例

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = CommonDataApplication.class)
@IntegrationTest
@EnableConfigurationProperties
public class CassandraClientTest {

    @Autowired
    CassandraClientNew cassandraClientNew;

    @Test
    public void test(){
        cassandraClientNew.getSession();
        System.out.println(" **** done ****");
    }
}
Run Code Online (Sandbox Code Playgroud)

它不是将junit设置为keyspaceApp,而是设置xyz.

看起来像prefix ="cassandra"无效

java spring spring-boot

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

在spring boot中将tomcat限制为某些ip地址

我需要将基于spring boot的应用程序的嵌入式tomcat限制为某些ip地址.我想只允许来自两个IP地址的传入连接,而不是全部.我知道如何在没有运行嵌入式的tomcat中执行此操作但不知道在spring boot中配置它的方法.各种server.tomcat.*属性似乎都没有为此提供支持.有一个属性server.address可以让我绑定到本地的IP地址,但这不是我需要的.

java security spring tomcat spring-boot

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

使用不带注释的@JsonIdentityInfo

我使用Jackson 2.2.3将POJO序列化为JSON。然后我遇到了一个问题,就是我无法序列化递归结构...我通过使用@JsonIdentityInfo=> 解决了这个问题,效果很好。

但是,我不希望此注释位于POJO的顶部。

所以我的问题是:还有其他可能性设置我的默认行为ObjectMapper以对每个POJO使用该功能吗?

所以我想转换这个注释代码

@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@id")
Run Code Online (Sandbox Code Playgroud)

ObjectMapper om = new ObjectMapper();
om.setDefaultIdentityInfo(ObjectIdGenerators.IntSequenceGenerator.class, "@id");
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

java serialization json jackson

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

标签 统计

java ×3

spring ×2

spring-boot ×2

jackson ×1

json ×1

security ×1

serialization ×1

tomcat ×1