LIVE NOTES
LIVE NOTES
Using ApplicationContext you can access any beans.
When we call from postman
Gson is autoconfigured
While creating one bean, you can inject another bean in @Bean method
When spring boot creates objects, it uses sensible default values.
Starters concept
Demo. your 1st demo on weekend -
Agile - SDLC
every 2 weeks, we have to give demo to the client.
Demo will help your to better prepare for explaining project during interview.
Demo is mandatory for your growth.
It company needs demos every 2 weeks.
Demo will prepare you for the interview.
Demo on project topic.
Technical + Conceptual.
Minimum 30 mins.
Laptop - your screen record, voice record.
The way you will explain during interview.
.7 demos.
OBS Studio, snipping tool.. recording
screen, audio
video
On your youtube as unlisted.
google form for tracking (email)
every week1 demos.
mandatory for completion letter.
5 demos, if attendance is 70% or more
7 demos, less than 70%
69.8%
=============================
Coding with Spring & Spring Boot.
IOC
Inversion of Control
Spring takes care of object creation & maintainence.
100 java classes
Spring asks dev to tell the framework, which classes should be managed by spring.
@Component (directly or indirectly @Service, @Res.... ) - Spring Bean
Container, Spring Container, IOC container..
======================================
memory space where spring manages spring beans..
How can 1 object have access to another object.
Constroller is dependent on service for running business logic. (calling a method)
so controller is called as dependent, and service => dependency.
Dependency injection
Dependency Lookup
Dependency injection
when spring is creating an object of dependent(controller) class, then it will automatically
assign the reference of dependency (service).
field injection
@Autowired
@Autowired is optional
constructor injection
parameterized contructor & in constructor this.x = x.
Lombok
@RequiredArgsConstructor
make field final.
================================
Dependency Lookup
the dependent class (controller) needs to ask for dependency (service)
Service Registry - lookup
when 1 MS wants to connect to another MS, you lookup the details of the
destination MS, and then you invoke
How to technically implement Dependency Lookup
We are using ApplicationContext container.
Spring creates an object of ApplicationContext & is available in container.
This ApplicationContext object has getBean(-), using that you can get any object.
when you do dependency lookup means,
AddService serviceRef = [Link]([Link]);
[Link]()
how can controller get access to "ApplicationContext object"
since both the objects are in container, we can ask spring to trigger dependency
injection.
Dont dependency inject AddService, rather dependency lookup.
================== Coding tips
Always keep spring boot application up & running with devtool depency. and then code.
incremental coding.
Whatever you change, you should know the impact in the code.
while you are tying take suggestions from IDE.
test every change, that you do.
- while coding use logical class, method, variable names, which relate to what that piece of code
does.
- think about clean code. where to give enter.. group related statements together. Readability.
==================
1. Get reference of ApplicationContext. (constructor inject)
2. call getBean - addService = [Link]([Link]);
You should belong as top 20% of IT industry.
---
ApplicationContext is an interface & spring has dependency injected its child class.
AnnotationConfigServletWebServerApplicationContext
============
find all beans which are there in container
vibe coding
// get list of all beans from application context
String[] allBean = [Link]();
[Link]("====>CONTROLLER All Beans in Application Context:");
for (String beanName : allBean) {
[Link]("Bean Name: {}", beanName);
}
- currently we noticed 178 beans in container.
- our user defined beans were there and also.. spring create lot of other beans...
- needing for your application to run.
UX designer
Product Owner
UX AI tool
Tech Team
=========================
throw & log exception in controller and check the flow:
- tomcat initially receives and processes
- give to spring
- HttpServelet
- spring
- java reflection api (we can call even private method)
- call your method.
============
How to make a java class as spring bean.
When you are writing code for new java class then you will use @Component.
What if you want predefined java class to be a spring bean.
already code by other libraries and available as jar file with you.
If you want predefined java classes to be made as spring bean
@Configuration
@Bean
We make Random to be constructor injected
and Random object is not in container, so spring boot failed to start..
You need to make that object available so spring can find it & give it to you.
-- predefined java clases (avaialbel in jar), you want to have objects of this in spring container,
so you can DI, DL whereever you need them.
We use @Configuration & @Bean
1. on service start, spring will read all java classes annotated with @Configuration
2. Spring will call all methods in that config class with @Bean
3. Your method logic will execute
4. You will return some value/object.
5. Whatever object we return spring maintainer it inside container
6. Once in container, you can DI, DL and call the methods that you want.
how to make a java class as spring bean:
1. When you are writing your own java classes, then use @Component or dependent..
2. if you want predefined java class, then use @Configuration & @Bean
Once its Spring bean DI DL
DI
=================
AutoConfiguration.
AddRequest is a java object => convert this to json.
Jackson lib to work with Json (default lib for spring boot)
Google Gson lib.
convert java object to json using Gson lib.
maven
[Link] dependency of Gson lib.
<dependency>
<groupId>[Link]</groupId>
<artifactId>gson</artifactId>
</dependency>
Gson gson = new Gson();
String jsonString = [Link](request);
============================
//const inject
private final Gson gson;
=====
String jsonString = [Link](request);
====
what will happen:
service startup failed
successful start, but run time failure
successful start, executes successfully.
===================== Gson
Spring boot AutoConfiguration
based on jar which is there in class path.. spring boot identifies what are important clases for
which spring beans needs to be created, and creates accordingly.
These spring beans are directly available in container. so developers dont have to configure it.
you can directly Dependency Inject or Dependency Lookup
=====================
what will happen if we also create Bean of Gson.
@Configuration & Bean
when developer is creating the object, then spring boot autoconfig not create it.
negative matches:
-----------------
GsonAutoConfiguration#gson:
Did not match:
- @ConditionalOnMissingBean (types: [Link]; SearchStrategy: all) found
beans of type '[Link]' gsonBean (OnBeanCondition)
=================
when developer did not config, then spring boot will check, that bean is not available, to it will
create the bean.
Positive matches:
-----------------
GsonAutoConfiguration#gson matched:
- @ConditionalOnMissingBean (types: [Link]; SearchStrategy: all) did not
find any beans (OnBeanCondition)
[Link]
java/org/springframework/boot/gson/autoconfigure/[Link]
@ConditionalOnMissingBean
if the bean is missing, then call this method to create bean.
if not missing, dont call.
----------------------------
====================
Auto Configuration
- creating the beans, so you dont have to create it by yourself.
- Sensible Default - spring boot uses intelligent default values. Good standards..
they have option, if developer wants to override, you can do it.
====================
spring boot starters
-----
spring will give you the primary jar files.
spring-boot-starter-web
it will give you the jar files needed to make a webapplication.
opinionated starters
Embeded servers - tomcat..
Embeded DB
Devtool depenendency
json, no xml
realtime health monitoring
actuactor
Spring Boot is AutoConfiguring
==========================
@SpringBootApplication
@Configuration + @EnableAutoConfiguration + @ComponentScan
AI SUmmary
Summary
Tausief S. emphasized the importance of following the daily checklist,
logging in from laptops, taking runtime notes, and submitting demos as
crucial for growth and interview preparation. Tausief S. reviewed Spring
core concepts including Inversion of Control (IOC), Spring Beans, Spring
Container, Application Context, Dependency Injection (DI), and Dependency
Lookup, and discussed best practices for coding, debugging, and
professional conduct. Tausief S. also introduced Spring Boot's auto-
configuration, sensible defaults, and starters, and highlighted the features
of the `@SpringBootApplication` annotation, which enables rapid
application development.
Details
● Meeting Logistics and Attendance Tausief S began the meeting by emphasizing
the importance of following the daily checklist, logging in from laptops, and
taking runtime notes (00:00:00). They announced that October 17th was the last
day for refunds and opting out, and that new session material would be moved to
a new Google Drive location starting next week (00:13:50). Daily attendance
tracking is implemented from Monday to Friday to encourage consistency, with
weekend attendance counting as Friday's (00:09:32).
● Demo Submission Importance Tausief S highlighted that the first demo is due by
the weekend and explained that demos are crucial for growth and interview
preparation (00:00:00) (00:02:45). They stressed that demos are mandatory for
receiving a completion letter, with five demos required for over 70% attendance
and seven for less than 70% (00:08:26). Tausief S also noted that agile
methodology mandates demos every two weeks to clients, making this practice
essential for industry readiness (00:02:45).
● Demo Guidelines and Content Demos should focus on project topics discussed
daily, include mandatory technical aspects alongside conceptual explanations,
and be a minimum of 30 minutes (00:03:57). Tausief S advised participants to
assume an interview question and explain their project implementation,
potentially writing and executing code (00:06:11). They also recommended
recording the screen and voice, speaking clearly as if in an interview, and
uploading the video to YouTube as an unlisted link (00:05:02) (00:07:13).
● Demo Self-Assessment and Improvement Participants are required to submit
their demo links via a Google Form, score their own demo from 1 to 5, and share
their main observations, including areas for improvement and future focus
(00:07:13) (00:11:32). Tausief S encouraged watching other members' demos to
learn and identify areas for personal growth (00:12:47). They also mentioned that
tips for giving better demos would be discussed in the following week (00:11:32).
● Accessing Session Materials and AI Summaries Tausief S informed participants
that all session materials, including recordings, Google Forms, attendance forms,
and task forms, are accessible via a single link in the Google Drive (00:13:50).
They also highlighted the availability of AI summaries for each session, which
can be used to quickly revise key topics and prepare for interviews (00:15:08).
● Importance of Action and Consistency Tausief S strongly encouraged
participants to take action, do practicals, and make demos, emphasizing that
growth comes from doing things rather than just sitting (00:17:41). They
underlined the importance of consistency over the seven weeks, pushing
participants to maintain pace and be proactive for better results (00:28:38).
● Spring Core Concepts: IOC and Spring Beans Tausief S reviewed Spring core
concepts, specifically Inversion of Control (IOC), where Spring manages object
creation, management, and release (00:18:52). They explained that developers
must tell Spring which classes to manage using annotations like `@Component`,
`@Service`, or `@Repository`, and such managed Java objects are called Spring
Beans (00:20:10).
● Spring Container and Application Context Tausief S clarified that Spring
manages objects within a memory space called a container, also known as the
Spring Container or IOC Container (00:20:10). They highlighted that Spring and
Spring Boot primarily use the Application Context container, which is the modern
container with rich features and is an extension of the Bean Factory container
(00:33:24). The Application Context object itself is available within the container
and provides access to all other managed beans (00:34:53).
● Dependency Injection (DI) Tausief S explained that Dependency Injection is when
Spring automatically assigns the reference of a dependency (e.g., a service) to a
dependent class (e.g., a controller) during the dependent class's object creation
(00:22:51) (00:28:38). They detailed two primary methods: field injection using
`@Autowired` and constructor injection, with Sonar recommendations favoring
constructor injection for its speed and optimization (00:24:27). Tausief S also
showed how Lombok annotations can simplify constructor injection (00:27:24).
● Dependency Lookup Tausief S introduced Dependency Lookup as a method
where the dependent class explicitly asks for the dependency, unlike injection
where it is automatically given (00:29:52) (00:32:27). They explained that this
involves getting access to the Application Context object and then calling its `get
Bean` method to retrieve the desired service (00:34:53). Tausief S provided a
human life example of "lunch injection" versus "food lookup" to clarify the
concepts (00:32:27).
● Coding and Debugging Best Practices Tausief S advised always running the
Spring Boot application with `devtool` dependency while coding to immediately
identify and resolve errors (00:42:56). They also stressed the importance of
knowing the impact of every code change and testing each change incrementally
to avoid large debugging efforts (00:45:14) (00:49:59). Tausief S emphasized
using IDE suggestions (Control + Space) to prevent typos and save time
(00:52:34).
● Professional Conduct and Performance Expectations Tausief S delivered a
strong message about accountability, stating that individuals who do not
understand their code or blindly copy from sources like ChatGPT without
comprehension will not be tolerated in the IT industry (00:46:16). They
emphasized that bad performance affects team dynamics and can lead to the
departure of good performers, highlighting the industry's need for capable,
valuable, and responsible professionals (00:47:38). Tausief S stated their aim to
push participants to become top 20% performers in the IT industry by expecting
high standards (00:51:02).
● Dependency Lookup and Spring Container Tausief S explained that
`[Link]` can be used to retrieve an object from the Spring container. They
noted that if the desired object is an interface, the container will return a child of
that interface. Tausief S demonstrated how to use an IDE's suggestion feature to
determine the return type when unsure, by initially typing `int` and letting the IDE
suggest the correct type (01:00:14). This approach allows for assigning the
returned value to an instance field, rather than a regular variable (01:01:20).
● Developer Testing and Application Flow Tausief S emphasized that developer
testing extends beyond Postman, requiring checks in logs and databases to
understand the "under the hood" operations. Tausief S detailed the application
flow when a call is made, starting with the `addition controller`, then the `add
service` instance being looked up, and the `add service constructor` being called
during service startup when Spring makes it a Spring bean (01:02:24). Tausief S
concluded that constructor injection and method calls simplify the process,
offering to share the code for reference (01:03:36).
● Discovering Beans in the Spring Container Tausief S demonstrated how to find
all beans within the Spring container using the `application context`. They
illustrated the use of AI pair programming or "vibe coding" with GitHub Copilot to
generate the code for retrieving a list of all beans by simply writing a comment
(01:04:48). Tausief S stressed the importance of understanding the AI-generated
code, recommending reviewing method descriptions and return types (01:05:53).
They also advised on code readability by grouping related statements and using
appropriate spacing (01:07:30).
● Analysis of Spring's Internal Beans Tausief S showed that a simple web
application with one REST API, like the `addition controller` and `addition service`,
leads Spring to create numerous internal objects, highlighting that Spring is "very
heavy" due to these internal beans (01:08:41). Tausief S copied the list of beans
and counted 178 default beans created by Spring, depending on jar files in the
class path (01:09:58). They observed that user-defined beans, such as `Addition
Controller` and `Add Service`, are present, and the main application class itself is
also treated as a Spring bean (01:11:06). Tausief S concluded that frameworks
like Spring handle a lot of background work, making them useful despite their
heavy nature, and noted that for memory-constrained environments, alternatives
like `bean factory container` might be considered (01:12:16).
● Impact of AI on Software Development Tausief S discussed the increasing
adoption of AI in coding tools, simplifying the development process (01:12:16).
They provided examples of how AI tools enable product owners to develop full
UI/UX screens and even small features without needing a UX designer or
technical team, even without coding knowledge (01:13:50). Tausief S predicted a
significant reduction in IT industry jobs (potentially 40%) for those unable to
adapt, emphasizing that individuals in the top 20% who understand complex
systems and can build applications will remain in demand (01:15:02). Tausief S
stated that while user experiences might simplify through AI, the underlying
technical systems will become more complex, requiring stronger developer
knowledge in areas like AI, MCPS, and AI agents (01:17:31). Tausief S cautioned
that AI is unreliable, necessitating more robust backend systems and continuous
skill upgrades for developers to leverage future opportunities (01:18:35).
● Debugging and Request Flow Analysis with Stack Traces Tausief S used
throwing an exception to demonstrate how to debug and understand the request
flow in a Spring Boot application using stack traces (01:21:08). They explained
that the stack trace reveals the entire journey of a request from Postman to a
specific line of code in the controller (01:23:47). Tausief S elaborated that the
embedded server (like Tomcat) initially receives and processes the request, then
passes control to the Spring framework, which utilizes HTTP servlets and Java
reflection API to call the application's methods, including private ones (01:25:02).
Tausief S highlighted that many of the objects required for this chain are
managed within the Spring container (01:27:57).
● Making Predefined Java Classes Spring Beans Tausief S addressed the
challenge of making predefined Java classes (like `Random`) that are not user-
editable, into Spring beans (01:31:53) (01:35:06). They explained that attempting
to constructor-inject such a class without defining it as a bean will cause the
Spring application to fail during startup (01:37:38). Tausief S introduced two
annotations, `@Configuration` and `@Bean`, as the solution for defining
predefined classes as Spring beans (01:36:24) (01:40:32). Tausief S
demonstrated that marking a class with `@Configuration` and then defining a
method within it that returns an object of the predefined class, annotated with
`@Bean`, enables Spring to create and manage that object in its container,
allowing for dependency injection. Tausief S emphasized that both
`@Configuration` and `@Bean` annotations are mandatory for this process to
work (01:41:42) (01:49:01).
● Introduction to Spring Boot's Auto-Configuration Tausief S introduced auto-
configuration as a powerful feature of Spring Boot, which they would explain
through practical demonstration rather than theory (01:52:51). They presented a
requirement to convert a Java object to JSON, mentioning that Spring Boot uses
Jackson library by default, but for demonstration, they would use the Google
JSON (GSON) library (01:54:18). Tausief S outlined the steps for integrating
GSON: adding its dependency to `[Link]`, preferably without specifying the
version to ensure compatibility with Spring Boot (01:56:40).
● Handling [Link] changes Tausief S explained that when the `[Link]` file is
changed, the current system should be stopped, a project clean performed if
required, and then the system should be rebuilt and restarted. This process helps
identify and fix issues early in the development cycle (01:59:07).
● Leveraging AI for Coding Assistance Tausief S demonstrated how to use AI
tools like ChatGPT to generate code snippets, such as converting a Java object
to JSON (02:00:18). They highlighted that these tools can quickly provide
solutions for common coding tasks, speeding up development (02:01:39).
● JSON Conversion and Format Tausief S showed how to convert a Java object
into a JSON string using simple methods and explained the JSON format as key-
value pairs with curly braces and comma-separated entries. This conversion was
successfully tested, confirming the ability to add the JSON library and perform
the conversion (02:02:50).
● Spring Boot Auto-configuration Tausief S explained Spring Boot's auto-
configuration feature, where Spring automatically creates and manages objects
(beans) based on the jars present in the classpath (02:15:50). They
demonstrated that if a developer does not explicitly configure a bean, Spring
Boot will auto-configure it, making the object available in the container
(02:32:21). Tausief S clarified that if a developer does configure a bean, Spring
Boot will not auto-configure it, avoiding duplication (02:31:13). This behavior is
achieved through annotations like `@ConditionalOnMissingBean`, which ensure a
bean is only created if it's not already present (02:37:47).
● Sensible Defaults in Spring Boot Tausief S introduced the concept of "sensible
defaults," where Spring Boot automatically assumes common and production-
ready default values for object fields during auto-configuration (02:40:04). This
feature allows developers to use objects without manual configuration for most
cases, though they can override these values if needed. Sensible defaults
contribute to rapid application development by pre-configuring objects with
intelligent values (02:41:56).
● Spring Boot Starters Tausief S discussed Spring Boot starters as a powerful
feature that simplifies dependency management by providing necessary jar files,
including main, dependent, and relevant (opinionated) ones (02:43:13)
(02:48:45). They explained that starters manage complex versioning and
dependencies, allowing developers to focus on functionality rather than manual
configuration (02:49:53) (02:57:03). Starters include common components like
embedded Tomcat servers and JSON libraries, which accelerate project setup
(02:45:02) (02:48:45).
● Other Key Spring Boot Features Tausief S outlined additional features of Spring
Boot, such as embedded servers (like Tomcat), embedded databases, and
developer tools for rapid application development (02:52:25). They also
mentioned minimal or no XML configuration, favoring Java code and JSON for
ease of use, and real-time health monitoring through actuators. These features
collectively enable the creation of standalone applications that run without
external setup (02:54:16).
● Spring Boot Features Tausief S. discussed Spring Boot's core features,
emphasizing its rapid application development capabilities as a standalone
application that uses an embedded Tomcat server, embedded databases,
opinionated starters, auto-configuration, and production-ready systems
(02:59:12). They noted that Spring Boot's power allows for building various
application types, including web and reactive applications (03:00:22).
● `@SpringBootApplication` Annotation Tausief S. explained that the
`@SpringBootApplication` annotation is the starting point for Spring Boot
applications, allowing a standalone application to run simply by executing its
main method (03:00:22). This annotation combines three features: Spring Boot
configuration, enable auto-configuration, and component scanning, which
together activate the container, create beans, manage dependency injections,
and bring the application to life (03:01:49). If any issues occur during this
process, the container will fail to start (03:03:21).
● Upcoming Topics and Recommendations Tausief S. concluded the week by
encouraging participants to complete the initial demo to foster growth and
enhance their skills (03:04:37). They also recommended further full-fledged
training online to gain more expertise and suggested learning about bean scope
concepts. Tausief S. outlined future topics for the next week, including REST API
standards, working with Git, coding REST controllers, packaging standards, and
setting up the PayPal provider service (03:05:37).