Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Aphorismen
Applications
Business Economics & Admin.
My Computers
Cooking
Devices
Folders
Food
Hardware
Infos
Software Development
Sports
Operation Instructions
Todos
Test
Help
Glossary
Community portal
adaptions
Sidebar anpassen
Wiki RB4
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
SpringBoot
(section)
Page
Discussion
English
Read
Edit
View history
Toolbox
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Concepts== * SpringBoot Autoconfiguration: by scanning the classpath * Dispatcher Servlet * SpringBoot Actuator (for monitoring) ===Architecture=== * Client -> Controller -> Service (Business Logic) -> Model ===[[Rest|Rest]]=== * see [https://spring.io/guides/tutorials/rest/ here] ===Application Context=== The '''ApplicationContext''' is where Spring holds instances of objects that it has identified to be managed and distributed automatically. These are called [[#Beans|Beans]]. The application context can also be autowired: @Autowired private ApplicationContext applicationContext; ===Dependency Injection=== ===Beans=== * Beans are specified by class level annotations e.g. <code>@Component, @Service, @Repository</code> etc. or by XML configuration. The annotations are hierachical meaning for example that there are more specialized annotations for <code>@Component</code>. *<code>@Bean</code> is a special annotation on method level. * A java class becomes Spring Bean only when it is created by Spring * On startup/runtime classes in the application will be scanned and each class annotated with spring annotations will be instantiated as beans and put into a global context (Spring applicationcontext). * Entities are no beans * You can autowire only those beans whose life-cycle are managed by Spring IoC container. * Spring support @Autowire only for Spring Beans * the default scope is singleton ===Security=== adding to <code>pom.xml</code>: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>'''spring-boot-starter-security'''</artifactId> </dependency> and update the project automatically sets up '''form-based authentication''' with a generated session cookie generated on the server or '''basic authentication''' with a header sent along with every request * user='user * pwd=see console output of server start or set it in <code>[[#Application_Properties|application.properties]]</code> spring.security.user.name=uwe spring.security.user.password=uwe This has to be entered just once. ===Testing=== <dependency> <groupId>org.springframework.boot</groupId> <artifactId>'''spring-boot-starter-test'''</artifactId> <scope>test</scope> </dependency> This integrates the frameworks JUnit, Hamcrest, Mockito, When you build a Spring boot application using Spring Initializer. It auto creates a <code>@SpringBootTest</code> annotated class for you with <code>contextLoads()</code> empty method. <code>@SpringBootTest</code> by default starts searching in the current package of the test class and then searches upwards through the package structure, looking for a class annotated with <code>@SpringBootConfiguration</code> from which it then reads the configuration to create an application context. ====TestRestTemplate==== * TestRestTemplate is part of the Spring Boot Test module and provides a high-level, programmatic way to test RESTful services by making actual HTTP requests to the service. It allows you to send HTTP requests (GET, POST, PUT, DELETE, etc.) to your application's REST endpoints and receive actual HTTP responses. * It starts an embedded server (typically an embedded Tomcat or Jetty instance) and sends requests to the server as if they were real HTTP requests. * TestRestTemplate is more suitable for integration testing and end-to-end testing because it interacts with the running server, making actual network calls. ====MockMvc==== * MockMvc, on the other hand, is a part of the Spring Test framework and is specifically designed for testing the controllers of your Spring application in isolation. * It allows you to perform requests against your controller methods without starting a full server. * With MockMvc, you can simulate HTTP requests and responses without making actual network calls. This makes it a more suitable choice for unit testing and integration testing of your Spring MVC controllers. * MockMvc provides a fluent and expressive API for setting up requests, sending them to your controllers, and then validating the results.
Summary:
Please note that all contributions to Wiki RB4 may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Uwe Heuer Wiki New:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width