我正在尝试更新它,WebSecurityConfigurerAdapter
因为它已被弃用。该类配置如下:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
UsuariService userDetailsService;
@Autowired
private AuthEntryPointJwt unauthorizedHandler;
@Bean
public AuthTokenFilter authenticationJwtTokenFilter() {
return new AuthTokenFilter();
}
@Override
public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
authenticationManagerBuilder.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().csrf().disable().exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().authorizeRequests()
.antMatchers("/api/auth/**").permitAll().antMatchers("/api/test/**").permitAll().antMatchers("/api/v1/**").permitAll().anyRequest()
.authenticated();
http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
}
}
Run Code Online (Sandbox Code Playgroud)
现在没有了WebSecurityConfigurerAdapter
我重新定义同一个类,如下所示:
@Configuration …
Run Code Online (Sandbox Code Playgroud) Could not find com.android.tools.build:gradle:7.3.3.
Searched in the following locations:
- https://plugins.gradle.org/m2/com/android/tools/build/gradle/7.3.3/gradle-7.3.3.pom
- https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/7.3.3/gradle-7.3.3.pom
Required by:
project:
Run Code Online (Sandbox Code Playgroud) brew cask install android-sdk
Run Code Online (Sandbox Code Playgroud)
警告:已经安装了 android-sdk 的 Cask。
brew cask reinstall android-sdk
Run Code Online (Sandbox Code Playgroud)
或者
brew cask uninstall android-sdk
Run Code Online (Sandbox Code Playgroud)
==> Caveats We will install android-sdk-tools, platform-tools, and build-tools for you. You can control android sdk packages via the
sdkmanager command. You may want to add to your profile: 'export
ANDROID_HOME=/usr/local/share/android-sdk'
This operation may take up to 10 minutes depending on your internet
connection. Please, be patient.
==> Downloading https://dl.google.com/android/repository/tools_r25.2.3-macosx.zip
Already downloaded:
/Users/ishandutta2007/Library/Caches/Homebrew/Cask/android-sdk--25.2.3.zip
==> Verifying checksum for Cask android-sdk Error: No such file …
Run Code Online (Sandbox Code Playgroud) 在 Spring Boot 单元测试中,如何模拟 @ConstructorBinding @ConfigurationProperties 数据类?
我想用不同的配置测试 FtpService (a @Service
,其中有 a )。RestTemplate
FtpService 的属性来自 Kotlin 数据类 - UrlProperties - 用ConstructorBinding
和注释@ConfigurationProperties
。
注意:FtpService 的构造函数从 UrlProperties 中提取属性。这意味着在Spring 加载 FtpService之前必须对 UrlProperties 进行模拟和存根
当我尝试模拟 UrlProperties 以便为不同的测试设置属性时,我要么收到错误,要么无法插入 bean
Cannot bind @ConfigurationProperties for bean 'urlProperties'. Ensure that @ConstructorBinding has not been applied to regular bean
Run Code Online (Sandbox Code Playgroud)
Cannot bind …
Run Code Online (Sandbox Code Playgroud) Execution failed for task ':app:checkDebugDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
> Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk8-1.7.20 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20)
Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk7-1.7.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.21)
Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations$ReflectSdkVersion found in modules jetified-kotlin-stdlib-1.8.0 (org.jetbrains.kotlin:kotlin-stdlib:1.8.0) and jetified-kotlin-stdlib-jdk7-1.7.21 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.21)
Run Code Online (Sandbox Code Playgroud) 使用 Gradle 8 和 Kotlin 1.8 编译时出现错误
compileDebugJavaWithJavac' task (current target is 1.8) and 'kaptGenerateStubsDebugKotlin' task (current target is 17)
jvm target compatibility should be set to the same Java version.
Run Code Online (Sandbox Code Playgroud)
这是一个多模块项目,问题仅发生在该模块上。但是,该模块也使用相同的 JVM 目标和兼容性目标。但这是怎么发生的呢?
这是我的这个模块的 Gradle:
plugins {
id 'com.android.library'
alias libs.plugins.kotlin.android.plugin
alias libs.plugins.kotlin.kapt.plugin
alias libs.plugins.dagger.hilt.module.plugin
}
android {
namespace 'com.lelestacia.network'
compileSdk 33
defaultConfig {
minSdk 24
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
} …
Run Code Online (Sandbox Code Playgroud) 我正在尝试为接口 Foo 编写参数化测试,该接口声明一个方法 getFooEventInt(int, int)。我编写了一个适用于 Foo 的单个实例(FooImpl 对象)的参数化测试。
public class FooTest {
@ParameterizedTest
@MethodSource("getFooEvenIntProvider")
public void getFooEvenIntTest(int seed, int expectedResult) {
Foo foo = new FooImpl();
Assertions.assertEquals(expectedResult, foo.getFooEvenInt(seed));
}
private static Stream getFooEvenIntProvider() {
return Stream.of(
Arguments.of(-2, 0),
Arguments.of(-1, 0),
Arguments.of( 0, 2),
Arguments.of( 1, 2),
);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我希望能够针对提供的 Foo 实现实例列表调用 getFooEvenIntTest(int, int) ,然后每次迭代都使用提供的种子/预期结果值列表。
我意识到我可以这样做...
public class FooTest {
@ParameterizedTest
@MethodSource("getFooProvider")
public void getFooImplEvenIntTest(Foo foo) {
int[] expectedResult = { 0, 0, 2, 2 };
int[] seed = { …
Run Code Online (Sandbox Code Playgroud) 我有一个问题,如何防止随机数重复。顺便问一下,有人可以向我解释如何对这些随机数进行排序吗?
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val textView = findViewById<TextView>(R.id.textView)
val button = findViewById<Button>(R.id.buttom)
button.setOnClickListener {
var liczba = List(6){Random.nextInt(1,69)}
textView.text = liczba.toString()
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用 Kotlin/JVM 1.8.0 和 Kotlinx 序列化 1.4.1。
我需要将 ajava.math.BigDecimal
和编码java.math.BigInteger
为 JSON。
我正在使用BigDecimal
and ,BigInteger
因为我想要编码的值可能大于 aDouble
可以容纳的值,而且我还想避免浮点精度的错误。我不想将数字编码为字符串,因为 JSON 是由其他程序读取的,因此它需要正确。
JSON 规范对数字的长度没有限制,所以应该是可能的。
当我尝试直接使用BigDecimal
and时BigInteger
,出现错误
import java.math.*
import kotlinx.serialization.*
import kotlinx.serialization.json.*
@Serializable
data class FooNumbers(
val decimal: BigDecimal,
val integer: BigInteger,
)
Run Code Online (Sandbox Code Playgroud)
Serializer has not been found for type 'BigDecimal'. To use context serializer as fallback, explicitly annotate type or property with @Contextual
Serializer has not been found for …
Run Code Online (Sandbox Code Playgroud) 我的 Minecraft 服务器有一个指标,mc_player_online
. 它显示1
玩家是否在线0
。
我可以用图表来显示有多少玩家在线。
我想计算 Minecraft 服务器上玩家的游戏时间。输出可以制成表格以显示“玩家 Steve 的游戏时间 = 2d 3h 45m”。
如何计算玩家在线时长?
我还想计算服务器的利用率。因此,如果服务器从 12:00 运行到 13:00,并且 10 个玩家在 12:00 同时登录并玩到 12:10,那么利用率应该是 10 分钟(而不是 10 * 10 分钟)。
如何计算指标 ( mc_player_online
) 高于阈值 (0) 的时间?
kotlin ×4
android ×3
gradle ×3
junit5 ×2
spring-boot ×2
bigdecimal ×1
build-script ×1
build.gradle ×1
homebrew ×1
java ×1
json ×1
jvm ×1
macos ×1
mockito ×1
nested ×1
prometheus ×1
random ×1
sorting ×1
unit-testing ×1