Know Before You Go: Spring Training Bag Policy Explained! (Easy Tips)

Date:

Share post:

Okay, so today I wanted to mess around with something called “training bag policy” in Spring. I’d heard about it, but honestly, I hadn’t ever actually tried it myself. So, I figured, why not? Let’s dive in and see what happens.

Know Before You Go: Spring Training Bag Policy Explained! (Easy Tips)

Getting Started

First things first, I needed a basic Spring Boot project. I just whipped up a simple one – you know, the usual: a couple of controllers, some services, the standard stuff. Nothing fancy, just enough to have something to work with.

Then I created the configuration for a training bean.

I made a simple configuration class.

java

@Configuration

Know Before You Go: Spring Training Bag Policy Explained! (Easy Tips)

public class TrainingBagConfig {

Then I created the bean.

java

@Configuration

public class TrainingBagConfig {

Know Before You Go: Spring Training Bag Policy Explained! (Easy Tips)

@Bean

public TrainingBag trainingBag(){

return new TrainingBag();

Then I created a very simple pojo, using lombok to quickly generate.

java

Know Before You Go: Spring Training Bag Policy Explained! (Easy Tips)

@Data

@NoArgsConstructor

@AllArgsConstructor

public class TrainingBag {

private String name;

Know Before You Go: Spring Training Bag Policy Explained! (Easy Tips)

private String color;

private Integer size;

private List strings;

The Experiment

So, the whole point was to play with different configurations.I started exploring.I try to configure it in the configuration class.

java

Know Before You Go: Spring Training Bag Policy Explained! (Easy Tips)

@Bean

public TrainingBag trainingBag(){

TrainingBag trainingBag = new TrainingBag();

*(“red”);

*(“My Red Bag”);

Know Before You Go: Spring Training Bag Policy Explained! (Easy Tips)

*(52);

return trainingBag;

I ran it and boom it * name is “My Red Bag”,the color is red,and the size is 52.

The I tried another way.I removed the above code and add @ConfigurationProperties

java

Know Before You Go: Spring Training Bag Policy Explained! (Easy Tips)

@Configuration

public class TrainingBagConfig {

@Bean

@ConfigurationProperties(prefix = “training”)

public TrainingBag trainingBag(){

Know Before You Go: Spring Training Bag Policy Explained! (Easy Tips)

return new TrainingBag();

Then, I add some config in *.

yaml

training:

name: “My Blue Bag”

Know Before You Go: Spring Training Bag Policy Explained! (Easy Tips)

color: blue

size: 48

strings:

– a

– b

Know Before You Go: Spring Training Bag Policy Explained! (Easy Tips)

– c

I ran it and It also * I knew how to use it.

Wrapping Up

It’s worked for my experiment. It’s a simple function, and a good way to try something I never used before. That’s the beauty of just trying things out – you learn by doing!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related articles

Easy Peasy 124 lbs to kg Conversion: We Show You How It Is Done for Everyone.

Alright, so today, I found myself needing to switch 124 pounds over to kilograms. It’s one of those...

Remember the awesome 1993 new york yankees roster? Relive the glory with every player name listed!

So, the other day, I got to thinking about baseball from a while back, specifically the early 90s....

Bronny James Jail news: Did LeBrons son really get into trouble? Find out the actual truth here.

My Encounter with the “Bronny James Jail” Story Alright, so the other day, this “Bronny James jail” thing popped...

What is the Bleacher Report class action settlement? Get the easy details you need to know.

So, I heard some buzz about this Bleacher Report class action settlement thing a while back. You know...