小编Ama*_*har的帖子

如何从终端执行 spring-boot:run 以进行远程调试

我正在尝试运行该./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)

java spring remote-debugging maven spring-boot

4
推荐指数
1
解决办法
5998
查看次数

spring-data-mongo 的 @PrePersist EventListener 替代方案

我创建了一个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)

GitHub 代码

如果我像这样实现我的代码,我需要sequenceRepository.getNextId(...)在保存之前调用每个文档。

在 JPA 中我们可以使用EventListeners@PrePersist. 是否有spring-data-mongo替代或类似的功能来实现这一目标?

mongodb spring-data spring-data-jpa kotlin spring-data-mongodb

4
推荐指数
1
解决办法
2760
查看次数

使用 GraalVM JDK 构建/运行您的应用程序

我正在尝试使用 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如果

java intellij-idea graalvm

3
推荐指数
1
解决办法
2616
查看次数

我想忽略JSON中的字段只在少数情况下是否可能?

我的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 spring json model spring-mvc

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