我已经使用Intellij Idea了很长一段时间了.我有几个问题.有没有办法从当前项目的所有文件中删除所有未使用的导入?
我知道我可以选择菜单项Code> Optimize Imports(CTRL + ALT + O)来组织单个文件中的导入,但由于我正在处理的应用程序有数百个文件,因此这个过程没有任何意义.如果没有办法做到这一点,我可以为此创建一个宏吗?如果是这样,我该怎么办?
我试图为我的应用程序启用 Spring Boot 管理服务器。默认设置工作得很好,但是当我尝试启用安全性时,出现以下错误:
应用程序无法启动
描述:
无法注册在类路径资源 [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class] 中定义的 bean 'conversionServicePostProcessor'。具有该名称的 bean 已经在类路径资源 [org/springframework/security/config/annotation/web/reactive/WebFluxSecurityConfiguration.class] 中定义并且覆盖被禁用。
行动:
考虑通过设置 spring.main.allow-bean-definition-overriding=true 重命名其中一个 bean 或启用覆盖
进程以退出代码 1 结束
我正在使用spring-boot-admin-starter-server(2.2.0-SNAPSHOT)的最新 SNAPSHOT 版本。这是我的安全配置:
@EnableAdminServer
@EnableWebFluxSecurity
@Configuration(proxyBeanMethods = false)
class AdminServerSecurityConfigurations(val adminServerProperties: AdminServerProperties) {
@Bean
fun adminServerSecurityWebFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain = http
// @formatter:off
.authorizeExchange()
.pathMatchers("${adminServerProperties.contextPath}/assets/**").permitAll()
.pathMatchers("${adminServerProperties.contextPath}/login").permitAll()
.anyExchange().authenticated().and()
.formLogin().loginPage("${adminServerProperties.contextPath}/login").and()
.logout().logoutUrl("${adminServerProperties.contextPath}/logout").and()
.httpBasic().and()
// @formatter:on
.csrf().disable()
.build()
@Bean
fun notifyLogger(instanceRepository: InstanceRepository) = LoggingNotifier(instanceRepository)
}
Run Code Online (Sandbox Code Playgroud) 我有一个A定义如下的类的对象列表:
class A {
private Set<String> sOne;
private Set<String> sTwo;
// Constructor, getters and setters
}
Run Code Online (Sandbox Code Playgroud)
现在我想创建一个包含两个要素流sOne和stwo。在Java 8中有没有办法做到这一点?
我已经Spring Boot使用创建了一个项目Kotlin。我想创建一个.jar包含所有依赖项的文件,以便我可以从命令行运行该应用程序。主类的 FQCN 是:com.example.Application.kt。我的配置中有以下配置pom.xml:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.example.Application</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
应用程序无法开始抱怨找不到 mainClass。这是异常示例:
Exception in thread "main" java.lang.ClassNotFoundException: com.example.Application
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:93)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:46)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
Run Code Online (Sandbox Code Playgroud)
我缺少什么?
我写了一个读取文本文件的代码。文本文件包含我想替换的占位符。替换不会以这种方式工作,并且字符串与占位符一起打印。这是我为此编写的代码:
class TestSub(val sub: Sub) {
fun create() = template()
fun template() = Files.newBufferedReader(ClassPathResource(templateId.location).file.toPath()).readText()
}
data class Sub(val name: String, val age: Int)
Run Code Online (Sandbox Code Playgroud)
这是尝试打印最终字符串的主要函数:
fun main(args: Array<String>) {
val sub = Sub("Prashant", 32)
println(TestSub(sub).create())
}
Run Code Online (Sandbox Code Playgroud)
但是,当我使用字符串而不是读取文件时,以下代码有效(替换fun template())
fun template() = "<h1>Hello ${sub.name}. Your age is ${sub.age}</h1>"
Run Code Online (Sandbox Code Playgroud)
有没有办法在读取文件内容时使字符串替换工作?
这看起来有点奇怪,但我不小心用 Kotlin 写了这段代码:
fun exchange(request: Request): ResponseEntity<*> = null!!
Run Code Online (Sandbox Code Playgroud)
IDE 似乎并没有抱怨。允许这样做吗?如果允许,为什么?
我想测试Java中无穷大是否等于无穷大:
Double.POSITIVE_INFINITY == Double.POSITIVE_INFINITY
Run Code Online (Sandbox Code Playgroud)
事实证明这是真实的,我对结果感到惊讶.我的问题是两个无限值如何相等?