Spring and Guice together, or just Spring

后端 未结 5 1969
盖世英雄少女心
盖世英雄少女心 2020-12-31 00:01

I\'m starting a new Java web app from scratch.

I don\'t have much experience on Spring Framework, but I know I\'d like to use some of its features, such as Transacc

5条回答
  •  北海茫月
    2020-12-31 00:45

    If you're just starting then I'll recommend you using https://github.com/spring-projects/spring-boot

    It has great autoconfiguration feature and saves writing boilerplate code. I even can release you from using application server due to embedded Tomcat. For example implementing simple MVC controller (which can be used as REST endpoints) looks like that:

    @Controller
    @EnableAutoConfiguration
    public class SampleController {
    
        @RequestMapping("/")
        @ResponseBody
        String home() {
            return "Hello World!";
        }
    
        public static void main(String[] args) throws Exception {
            SpringApplication.run(SampleController.class, args);
        }
    }
    

    Now you can execute java -jar your_package.jar and thats all. You will also get transaction management, database integration, etc. More examples can be found in mentioned link, especially in https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples directory

提交回复
热议问题