我正在尝试运行该./mvnw spring-boot:run命令,以便可以对该进程进行远程调试。
我试过
./mvnw exec:exec
-Dexec.executable="java"
-Dexec.args="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"
spring-boot:run
Run Code Online (Sandbox Code Playgroud)
我得到了日志 Listening for transport dt_socket at address: 5005
但是我收到错误并且 maven 进程退出
[INFO] --- exec-maven-plugin:1.5.0:exec (default-cli) @ sample-project ---
Listening for transport dt_socket at address: 5005
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-server to select …Run Code Online (Sandbox Code Playgroud) 我创建了一个Repository自动递增 id 的方法@Document,但现在我需要显式调用@Idsetter 方法来设置新的 id。有没有一种方法可以使用 JPA 中的侦听器来做到这一点@PrePersist
@Repository
interface UserRepository : MongoRepository<User, Long>, UserRepositoryCustom
interface UserRepositoryCustom {
fun save(user: User): User
}
class UserRepositoryImpl(private val mongoOperations: MongoOperations, private val sequenceRepository: SequenceRepository) : UserRepositoryCustom {
override fun save(user: User): User {
// need to call this line for every @Document
user.id = sequenceRepository.getNextId(User.SEQUENCE_KEY)
mongoOperations.insert(user)
return user
}
}
Run Code Online (Sandbox Code Playgroud)
如果我像这样实现我的代码,我需要sequenceRepository.getNextId(...)在保存之前调用每个文档。
在 JPA 中我们可以使用EventListeners像@PrePersist. 是否有spring-data-mongo替代或类似的功能来实现这一目标?
mongodb spring-data spring-data-jpa kotlin spring-data-mongodb
我正在尝试使用 GraalVM JDK 来构建我的应用程序。我在“平台设置> SDK”中添加了 GraalVM JDK 并选择了它,然后单击“确定”。
当我构建我的项目时,我可以看到它仍在使用不同的“java”可执行文件。
/../_sandbox/lib/jdk8.0.222/bin/java -Dmaven.multiModuleProjectDirectory=/../Desktop/_sandbox/someproject "-Dmaven.home=/../Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/192.7142.36/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3" -Didea.modules.paths.file=/../Library/Caches/IntelliJIdea2019.2/Maven/idea-projects-state-3333fba9.properties -Dclassworlds.conf=/private/var/folders/2g/9fxnhqts6qsf_h81cnbts8tc0000gn/T/idea-7-mvn.conf "-Dmaven.ext.class.path=/../Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/192.7142.36/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven-event-listener.jar" "-javaagent:/../Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/192.7142.36/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=49971:/../Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/192.7142.36/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/../Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/192.7142.36/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/boot/plexus-classworlds-2.6.0.jar" org.codehaus.classworlds.Launcher -Didea.version2019.2.4 clean install
Picked up JAVA_TOOL_OPTIONS: -Duser.timezone=Etc/UTC -XX:+UseJVMCICompiler
Unrecognized VM option 'UseJVMCICompiler'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Run Code Online (Sandbox Code Playgroud)
我在 GraalVM 上使用“-XX:+UseJVMCICompiler”标志,因为普通的 JDK1.8 不支持该标志,所以我收到错误消息。
我希望java路径是/../_sandbox/lib/graalvm-ce-java8-19.3.0/Contents/Home/bin/java如果
我的ModelClass
public class UserPojo{
private String userEmailId;
private String userPassword;
private String userContactNumber;
//setters and getters
}
Run Code Online (Sandbox Code Playgroud)
我想将UserPojo类对象作为json发送,但在某些情况下,我希望使用userpassword发送,有些情况下没有userpassword可能会发送吗?
在下面的方法中,我想发送没有userpassword的userPojo对象.我的Spring版本是4.3.1.RELEASE.我有杰克逊图书馆
@RestController
@RequestMapping("/user")
public class UserController{
@GetMapping(value="/{userId}")
public UserPojo getUser(@PathVariable("userId") String userId){
//code goes here
//finally returning UserPojo Object
return userPojo;
}
}
Run Code Online (Sandbox Code Playgroud)
在下面的方法中我想用密码发送userPojo对象
@RestController
@RequestMapping("/admin")
public class AdminController{
@GetMapping(value="/{userId}")
public UserPojo getUser(@PathVariable("userId") String userId){
//code goes here
//finally returning UserPojo Object
return userPojo;
}
Run Code Online (Sandbox Code Playgroud)
}
我希望你明白我的观点
java ×3
spring ×2
graalvm ×1
json ×1
kotlin ×1
maven ×1
model ×1
mongodb ×1
spring-boot ×1
spring-data ×1
spring-mvc ×1