pf4j / pf4j-spring

Plugin Framework for Spring (PF4J - Spring Framework integration)
Apache License 2.0
338 stars 105 forks source link

Jpa in plug-in not working #65

Open guozhi72 opened 3 years ago

guozhi72 commented 3 years ago

Hi: I followed https://github.com/pf4j/pf4j-spring/issues/27 I couldn’t make it work. Can somebody past entire code which include rest controller and jpa in plug-in. I am surprised I could not find single example.

my controller to get list of entity which use jpa find all return null to postman. I put logging in the code. Before find all, message is logged. After fin fall, message didn’t show.

guozhi72 commented 3 years ago

In below plugin controler, localhost:8080/student-controller/s1, some time I got message null, some time found Not found. But based on the loging,

2021-06-19 09:36:27.302 INFO 9740 --- [nio-8080-exec-5] com.houston.plugin.StudentPlugin : 1111 2021-06-19 09:36:27.306 INFO 9740 --- [nio-8080-exec-5] com.houston.plugin.StudentPlugin : 1111cccc exception={0}

exception happended, I followed https://github.com/pf4j/pf4j-spring/issues/27, have not idea what is wrong( if I move my model and repository to main app, all works. )

@Controller @RequestMapping("/student-controller") public class PluginController {

private static final Logger log = LoggerFactory.getLogger( StudentPlugin.class);

// @Autowired private StudentRepository studentRepository ;

@GetMapping
public ResponseEntity<String> greetStudent(){
    return ResponseEntity.ok().body("Hello from student plugin");
}

@GetMapping("/s1")
public List<Student> getAllStudents() {

    //pm.loadPlugins();

    //pm.startPlugins();
    log.info("1111");
    List<Student> students = null;
    try{
        students = studentRepository.findAll();
        log.info("1111aaaa");
        log.info(MessageFormat.format("*** number={0} students found ", String.valueOf(students.size())));
    }
    catch(PersistenceException e)
    {
        log.info("1111bbbb exception={0}", e.getMessage());
    }
    catch( Exception e){
        log.info("1111cccc exception={0}", e.getMessage());
    }

    return students;
}

}