Questions tagged [spring]

Spring is a module based open source framework to build robust Java / Java EE applications.

The core feature of the Spring framework is its Dependency Injection and Inversion of Control. Beside this feature Spring provides several modules to extends its feature richness.

This tag should be used when your question is related to the usage of the Spring framework and its APIs and techniques. As Spring has a broad range of sub-modules you should consider to use a more specific tag if you have a question to one of this sub-modules. For example if your question is about the MVC module then you should use the spring-mvc tag too. To avoid unneeded callbacks to your question ensure to make clear which version of Spring you are using.

Before posting a question you should at least read the introducing of the Spring reference documentation as it gives you a good summary about the framework. Also you should read the section about the core technologies.

292 questions
262
votes
7 answers

What does the Spring framework do? Should I use it? Why or why not?

So, I'm starting a brand-new project in Java, and am considering using Spring. Why am I considering Spring? Because lots of people tell me I should use Spring! Seriously, any time I've tried to get people to explain what exactly Spring is or what…
sangfroid
  • 3,219
  • 4
  • 17
  • 12
57
votes
4 answers

Are there exceptional cases where we can accept duplicate code?

I'm working on a software project where we have to build three APIs. One for the home banking channel, one for the agency channel and a third for the mobile channel. The agency API is the most complete one as it has all the functionalities .. then a…
Mohamed Amine Mrad
  • 733
  • 1
  • 7
  • 12
55
votes
4 answers

Why do we need frameworks for dependency injection?

I've been reading up more on the Inversion of Control principle and Dependency Injection as an implementation of it and am pretty sure I understand it. It seems to be basically saying 'don't declare your class members' instantiations within the…
49
votes
1 answer

What is the use of DTO instead of Entity?

I am working on RCP application, I'm new to this application. Spring beans are used to write business logic to save/fetch entities. But, instead of sending entities directly to client we are converting to DTOs and populating client. While saving, we…
Naveen Kocherla
  • 613
  • 1
  • 6
  • 5
44
votes
6 answers

Why not Spring framework?

Are there any disadvantages in tying my application to Spring framework? I'm not talking about bugs or issues like that, if any. I'm talking about strategic, architectural things that will influence my application lifecycle. Should I prefer Spring…
Mike
  • 551
  • 1
  • 4
  • 5
41
votes
6 answers

Which classes should be autowired by Spring (when to use dependency injection)?

I have been using Dependency Injection in Spring for some time now, and I understand how it works and what are some pros and cons of using it. However, when I'm creating a new class I often wonder - Should this class be managed by Spring IOC…
Kacper86
  • 527
  • 1
  • 4
  • 6
31
votes
6 answers

In which layer should validation be located?

I'm creating a Rest API using Spring Boot and I am using Hibernate Validation to validate request inputs. But I also need other kinds of validation, for example when update data needs to checked, if the company id doesn't exist I want to throw a…
fdarmanto
  • 411
  • 1
  • 4
  • 3
31
votes
3 answers

Should service layer catch all dao exceptions and wrap them as service exceptions?

I have three layer Spring web app: dao, service and controllers. A controller never calls directly the dao, it does it through the service layer. Right now, most of the time if there is dao exception (runtime) that is not handled, it'll be caught…
Oscar
  • 453
  • 1
  • 4
  • 7
22
votes
3 answers

API Gateway (REST) + Event-Driven Microservices

I have a bunch of microservices whose functionality I expose through a REST API according to the API Gateway pattern. As these microservices are Spring Boot applications, I am using Spring AMQP to achieve RPC-style synchronous communication between…
19
votes
1 answer

Java application structure: Horizontal vs vertical split

Having a bit of a debate about the starting project structure (using Maven/Eclipse) for a big Java application. Option 1: entities (i.e. the whole database using Hibernate classes-first) services (i.e. sets of read/write operations on the…
Steve Chambers
  • 307
  • 2
  • 8
19
votes
5 answers

Do I need to know servlets and JSP to learn spring or hibernate or any other java web frameworks?

I've been asking a lot of people where to start learning java web development, I already know core java (Threading,Generics,Collections, a little experience with (JDBC)) but I do not know JSPs and servlets. I did my fair share of development with…
KyelJmD
  • 971
  • 5
  • 10
  • 20
18
votes
2 answers

Where to put Spring configuration file?

I want to integrate Spring framework in my project especially into server side. So, I don't want to put it within WEB-INF folder of war file. Should I put an applicationContext.xml it into each layer (means each project since divided in distinct…
Mik378
  • 3,838
  • 7
  • 33
  • 60
17
votes
4 answers

When not to use Spring to instantiate a bean?

I am trying to understand what would be the correct usage of Spring. Not syntactically, but in term of its purpose. If one is using Spring, then should Spring code replace all bean instantiation code? When to use or when not to use Spring, to…
Rishabh
  • 355
  • 1
  • 2
  • 7
16
votes
3 answers

“Depend on abstractions, not on concretions” what is the exact meaning of this term

I was reading SOLID principles on a website, in which for D - Dependency Inversion Principle it says: “Depend on abstractions, not on concretions” In other words. we should design our software in such a way that various modules can be separated…
kulsin
  • 275
  • 1
  • 2
  • 9
16
votes
3 answers

Java: Is it okay to abuse Spring beans (@Component) rather than use static final utility classes?

I'm torn between using DI and static utility classes on my code. I currently created a DateUtil static class that is only meant to be accessed statically. This class is responsible for just creating and manipulating dates using a variety of…
mpmp
  • 781
  • 3
  • 8
  • 12
1
2 3
19 20