Spring and Guice together, or just Spring

Spring has had Java-based annotation config for two major releases now. You don't need to write a single line of XML (not even a web.xml!)

I've worked with Guice and Spring. Guice is sufficient for smaller projects that need DI, but if you're going to be using Spring for MVC or transactional support you might as well just use its DI as well. Guice also doesn't have good profile support the way Spring does -- you have to do your own manual switching of modules if you want to have separate beans for local development, test environments, and production.


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. It 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


I think Spring alone is good enough for enterprise application.

Spring doesn't need XML too!!! Modern Spring Apps uses JavaConfig and minimal configuration. Take look at Spring Boot Guides. Whole Spring apps can not use any XML at all.

Guice is nice, but very limited. With Spring is possible to write web application or REST application with transactions and persistance very easy and fast. With Guice this is more complicated.