r/javahelp • • Apr 13 '24

Can you become a really good Java developer if you don't learn how to manually create beans?

So I've been able to do a lot of personal applications without manually creating beans in XML files. In the "real" world, are you somehow forced or you need to know how to manually create beans in XML files? I've been able to get by with just the annotation way of marking classes and objects as Spring Beans. Would love to hear everyones input for this.

1 Upvotes

23 comments sorted by

•

u/AutoModerator Apr 13 '24

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions

  • You include any and all error messages in full

  • You ask clear questions

  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

17

u/smutje187 Apr 13 '24

No JEE/Jakarta EE or Spring application I worked on during the last 12 years used XML descriptors for beans anymore.

3

u/South_Dig_9172 Apr 13 '24

thank god. thank you for commenting. I was re-learning Spring by reading the Spring framework again and got overwhelmed with the XML files and creating beans that way.

7

u/GuyWithLag Apr 13 '24

... dude, you need to start with Spring Boot...

1

u/South_Dig_9172 Apr 13 '24

nice thanks btw. I didn't know or I guess it somehow didn't occur to me that there was the Spring Boot docs lol

can I also know the most preferred way of validation? Do people use the Validator interface and dataBinder or do people validate data by using @ Valid with Annotations in the DTO object?

1

u/HansGetZeTomatensaft Apr 14 '24

I've only ever used and seen used the @Valid annotation.

1

u/xanyook Apr 14 '24

Last time I touch and XML descriptor was 9 years ago on a legacy application. Don't spend time on it, it would be wasted

11

u/GuyWithLag Apr 13 '24

I have. The first point of order is to replace that mess with annotations.

1

u/over_clockwise Apr 13 '24

Is there a nice way to automate that? I had to manually migrate thousands of lines of spring XML and it left me suicidal!

3

u/GuyWithLag Apr 14 '24

Openrewrite may have that by now..

1

u/South_Dig_9172 Apr 13 '24

One more question, for data validation, what do you see is used more often? currently I've been doing using the RequestBody Annotation followed by the Valid annotation with validation annotations on the DTO, but currently I learned about the Validator annotation and the BindingResult

1

u/Jujumofu Apr 13 '24

So im doing a software development bachelor right now, around halfway through.

Way to theoretic at the start and alot of stuff about stakeholder management.

I just did my exam in my Java for Enterprise applications which had alot going on with beans, jsf, hibernate and the pom.xml.

I see this thread and think "neat, something in the Java-sub I might have a clue about, the studies seem to go well".

Just to read that no one actually uses it anymore. Aint even mad, cause thats exactly what I expected tbh.

3

u/smutje187 Apr 13 '24

The concepts behind all these things are still valid. Server-side rendering has a resurgence, I used Hibernate/JPA and Maven in my last and current projects.

2

u/Jujumofu Apr 13 '24

Thats lovely to hear! Excited where it goes from here on.

2

u/fakeaccountlel1123 Apr 13 '24

hibernate is still popular, used a lot at my work (although some folks online may not be fans of it :)) and we use beans everywhere in our spring applications, just declared through annotations and not through xml. So you're still learning relevant stuff. Cant speak to jsf though.

2

u/Jujumofu Apr 13 '24

In this case I was completly mistaken and my criticism was wrong. We created the beans through the @Enitity annotation + whatever scope fit.

10

u/GuyWithLag Apr 13 '24

manually creating beans in XML

The 00's called, they want their XML back.

5

u/Daedalus9000 Java Developer Apr 14 '24

I would argue becoming "a really good Java developer" has nothing to do with what frameworks your employer uses and more about actually being good at implementing what is required of you. That being said, Spring has long since supported @Configuration and most frameworks (not all) have moved away from XML, so unless you work on an older application you are unlikely to find yourself supporting that style of config.

3

u/joranstark018 Apr 13 '24

We have a mix, some of our legacy systems partially use XML configuration.

1

u/pronuntiator Apr 14 '24 edited Apr 16 '24

If you are using Spring, you will occasionally create beans manually, just not in XML but with JavaConfig using the @Bean annotation. For example to configure two datasources. You should at least know about the scopes (singleton, request, …) and how to resolve duplicate bean conflicts.

Many older enterprise projects I work with (ten years or older) still use XML config, and we will not change that in the foreseeable future for existing applications; there is no business value in that. It's just two notation variants of the same thing.

Of course, as others wrote, this has nothing to do with "becoming a good Java developer" since beans are not a concept of the language.

1

u/Dense_Age_1795 Apr 14 '24

really depends, isn't needed but it's good to know you will never know what legacy code can you work

1

u/wildjokers Apr 14 '24

So first Spring != Java. I think you meant to ask if you can become a really good Spring developer if you don't learn how to manually create beans.

The answer is yes. Creating beans via XML is only going to be seen in legacy projects that haven't bothered to change to annotations. Wiring Spring up with XML is a plain nightmare. Honestly configuration via annotations and then Spring Boot saved Spring from falling into obscurity because of its previous configuration nightmare.