<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[mire]]></title><description><![CDATA[mire]]></description><link>https://mire.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 22 Oct 2026 20:22:57 GMT</lastBuildDate><atom:link href="https://mire.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[BeanFactory vs ApplicationContext]]></title><link>https://mire.hashnode.dev/beanfactory-vs-applicationcontext</link><guid isPermaLink="true">https://mire.hashnode.dev/beanfactory-vs-applicationcontext</guid><category><![CDATA[software development]]></category><category><![CDATA[Spring]]></category><category><![CDATA[Springboot]]></category><category><![CDATA[Java]]></category><dc:creator><![CDATA[Mirko Djuric]]></dc:creator><pubDate>Wed, 06 Oct 2021 17:02:49 GMT</pubDate><content:encoded><![CDATA[<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1633537789520/ziI1dFz2C.png" alt="bfvsac.png" /></p>
]]></content:encoded></item><item><title><![CDATA[HTTP Methods, Idempotent, Status code and other]]></title><description><![CDATA[The GET method request a representation of the specified resource. Request using GET method should only retrieve data. In other words, GET method is used…]]></description><link>https://mire.hashnode.dev/http-methods-idempotent-status-code-and-other</link><guid isPermaLink="true">https://mire.hashnode.dev/http-methods-idempotent-status-code-and-other</guid><category><![CDATA[http]]></category><dc:creator><![CDATA[Mirko Djuric]]></dc:creator><pubDate>Wed, 24 Mar 2021 18:00:38 GMT</pubDate><content:encoded><![CDATA[<h1 id="http-methods-you-must-know">HTTP Methods you must know</h1>
<h3 id="get-method">GET Method</h3>
<p>The GET method request a representation of the specified resource. Request using GET method should only retrieve data. In other words, GET method is used to "read". GET method returns a representation in XML or JSOn and HTTP response code 200 (OK). In an error case, it most often returns a 404 (NOT FOUND) or 400 (BAD REQUEST).
Calling it once has the same effect as calling it 20 times, or none at all. GET is idempotent, which means that making multiple identical request ends up having the same result as a single request</p>
<h3 id="post-method">POST Method</h3>
<p>The POST method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server. POST is used to "create" new resource.
POST is neither safe nor idempotent. It is recommended for non-idempotent request. Making two identical POST request will most-likely result in two resource containing the same information. Returs status 201 on successful creation</p>
<h3 id="put-method">PUT Method</h3>
<p>The PUT method replaces all current representations of the rarget resource with the request payload. PUT is most-often utilized for "update". On successful update, returns 200 and if we use to create resource it returns 201. PUT is not a safe operation, in that it modifies (or creates) state on the server, but it is idempotent. In other words, if you create or update a resource using PUT and then make that same call again, the resource is still there and still has the same state as it did with the first call.</p>
<h3 id="delete-method">DELETE Method</h3>
<p>The DELETE method deletes the specified resource. It use to "delete" resource from server. On successful deletion, return HTTP status 200 (OK) along with a response body, perhaps the representation of the deleted item. Calling DELETE on a resource a second time will often return a 404 (NOT FOUND) since it was already removed and therefore is no longer findable. </p>
<h1 id="idempotent">IDEMPOTENT</h1>
<p>An HTTP method is idempotent if an identical request can be made once or several times in a row with the same effect while leaving the server in the same state. GET, HEAD, PUT, and DELETE methods are idempotent, but not the POST method. All safe methods are also idempotent.</p>
<p>GET /page is idempotent. The client gets the same results every time he calls</p>
<p>DELETE /page is idempotent, even if the return status code may change between</p>
<p>but</p>
<p>POST /add_row is <code>not idempotent</code>; if it called several times, it adds several rows</p>
<h1 id="safe">SAFE</h1>
<p>HTTP methods are safe if it doesn't alter the state of the server. Several common HTTP methods are: GET, HEAD, OPTIONS. All safe methods are idempotent but bot all idempotent methods are safe, PUT and DELETE are both idempotent but unsafe, because they change state of the server</p>
<h1 id="status-codes">Status codes</h1>
<ol>
<li>Informational responses (100–199)</li>
<li>Successful responses (200–299)</li>
<li>Redirects (300–399)</li>
<li>Client errors (400–499)</li>
<li>Server errors (500–599)</li>
</ol>
<h3 id="information-responses">Information responses</h3>
<h4 id="100-continue">100 Continue</h4>
<p>This interim response indicates that everything so far is OK and that the client should continue the request, or ignore the response if the request is already finished.</p>
<h4 id="101-switching-protocol">101 Switching Protocol</h4>
<p>This code is sent in response to an Upgrade request header from the client, and indicates the protocol the server is switching to.</p>
<h4 id="102-processing-webdav">102 Processing (WebDAV)</h4>
<p>This code indicates that the server has received and is processing the request, but no response is available yet.</p>
<h4 id="103-early-hints">103 Early Hints</h4>
<p>This status code is primarily intended to be used with the Link header, letting the user agent start preloading resources while the server prepares a response.</p>
<h3 id="successful-responses">Successful responses</h3>
<h4 id="200-ok">200 OK</h4>
<p>The request has succeeded. The meaning of the success depends on the HTTP method:
GET: The resource has been fetched and is transmitted in the message body.
HEAD: The entity headers are in the message body.
PUT or POST: The resource describing the result of the action is transmitted in the message body.
TRACE: The message body contains the request message as received by the server.</p>
<h4 id="201-created">201 Created</h4>
<p>The request has succeeded and a new resource has been created as a result. This is typically the response sent after POST requests, or some PUT requests.</p>
<h4 id="202-accepted">202 Accepted</h4>
<p>The request has been received but not yet acted upon. It is noncommittal, since there is no way in HTTP to later send an asynchronous response indicating the outcome of the request. It is intended for cases where another process or server handles the request, or for batch processing.</p>
<h4 id="203-non-authoritative-information">203 Non-Authoritative Information</h4>
<p>This response code means the returned meta-information is not exactly the same as is available from the origin server, but is collected from a local or a third-party copy. This is mostly used for mirrors or backups of another resource. Except for that specific case, the "200 OK" response is preferred to this status.</p>
<h4 id="204-no-content">204 No Content</h4>
<p>There is no content to send for this request, but the headers may be useful. The user-agent may update its cached headers for this resource with the new ones.</p>
<h4 id="205-reset-content">205 Reset Content</h4>
<p>Tells the user-agent to reset the document which sent this request.</p>
<h4 id="206-partial-content">206 Partial Content</h4>
<p>This response code is used when the Range header is sent from the client to request only part of a resource.</p>
<h4 id="207-multi-status-webdav">207 Multi-Status (WebDAV)</h4>
<p>Conveys information about multiple resources, for situations where multiple status codes might be appropriate.</p>
<h4 id="208-already-reported-webdav">208 Already Reported (WebDAV)</h4>
<p>Used inside a  response element to avoid repeatedly enumerating the internal members of multiple bindings to the same collection.
226 IM Used (HTTP Delta encoding)
The server has fulfilled a GET request for the resource, and the response is a representation of the result of one or more instance-manipulations applied to the current instance.</p>
<h3 id="redirection-messages">Redirection messages</h3>
<h4 id="300-multiple-choice">300 Multiple Choice</h4>
<p>The request has more than one possible response. The user-agent or user should choose one of them. (There is no standardized way of choosing one of the responses, but HTML links to the possibilities are recommended so the user can pick.)</p>
<h4 id="301-moved-permanently">301 Moved Permanently</h4>
<p>The URL of the requested resource has been changed permanently. The new URL is given in the response.</p>
<h4 id="302-found">302 Found</h4>
<p>This response code means that the URI of requested resource has been changed temporarily. Further changes in the URI might be made in the future. Therefore, this same URI should be used by the client in future requests.</p>
<h4 id="303-see-other">303 See Other</h4>
<p>The server sent this response to direct the client to get the requested resource at another URI with a GET request.</p>
<h4 id="304-not-modified">304 Not Modified</h4>
<p>This is used for caching purposes. It tells the client that the response has not been modified, so the client can continue to use the same cached version of the response.</p>
<h4 id="305-use-proxy">305 Use Proxy</h4>
<p>Defined in a previous version of the HTTP specification to indicate that a requested response must be accessed by a proxy. It has been deprecated due to security concerns regarding in-band configuration of a proxy.</p>
<h4 id="306-unused">306 unused</h4>
<p>This response code is no longer used; it is just reserved. It was used in a previous version of the HTTP/1.1 specification.</p>
<h4 id="307-temporary-redirect">307 Temporary Redirect</h4>
<p>The server sends this response to direct the client to get the requested resource at another URI with same method that was used in the prior request. This has the same semantics as the 302 Found HTTP response code, with the exception that the user agent must not change the HTTP method used: If a POST was used in the first request, a POST must be used in the second request.</p>
<h4 id="308-permanent-redirect">308 Permanent Redirect</h4>
<p>This means that the resource is now permanently located at another URI, specified by the Location: HTTP Response header. This has the same semantics as the 301 Moved Permanently HTTP response code, with the exception that the user agent must not change the HTTP method used: If a POST was used in the first request, a POST must be used in the second request.</p>
<p>###Client error responses</p>
<h4 id="400-bad-request">400 Bad Request</h4>
<p>The server could not understand the request due to invalid syntax.</p>
<h4 id="401-unauthorized">401 Unauthorized</h4>
<p>Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.</p>
<h4 id="402-payment-required">402 Payment Required</h4>
<p>This response code is reserved for future use. The initial aim for creating this code was using it for digital payment systems, however this status code is used very rarely and no standard convention exists.</p>
<h4 id="403-forbidden">403 Forbidden</h4>
<p>The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401, the client's identity is known to the server.</p>
<h4 id="404-not-found">404 Not Found</h4>
<p>The server can not find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 to hide the existence of a resource from an unauthorized client. This response code is probably the most famous one due to its frequent occurrence on the web.</p>
<h4 id="405-method-not-allowed">405 Method Not Allowed</h4>
<p>The request method is known by the server but has been disabled and cannot be used. For example, an API may forbid DELETE-ing a resource. The two mandatory methods, GET and HEAD, must never be disabled and should not return this error code.</p>
<h4 id="406-not-acceptable">406 Not Acceptable</h4>
<p>This response is sent when the web server, after performing server-driven content negotiation, doesn't find any content that conforms to the criteria given by the user agent.</p>
<h4 id="407-proxy-authentication-required">407 Proxy Authentication Required</h4>
<p>This is similar to 401 but authentication is needed to be done by a proxy.</p>
<h4 id="408-request-timeout">408 Request Timeout</h4>
<p>This response is sent on an idle connection by some servers, even without any previous request by the client. It means that the server would like to shut down this unused connection. This response is used much more since some browsers, like Chrome, Firefox 27+, or IE9, use HTTP pre-connection mechanisms to speed up surfing. Also note that some servers merely shut down the connection without sending this message.</p>
<h4 id="409-conflict">409 Conflict</h4>
<p>This response is sent when a request conflicts with the current state of the server.</p>
<h4 id="410-gone">410 Gone</h4>
<p>This response is sent when the requested content has been permanently deleted from server, with no forwarding address. Clients are expected to remove their caches and links to the resource. The HTTP specification intends this status code to be used for "limited-time, promotional services". APIs should not feel compelled to indicate resources that have been deleted with this status code.</p>
<h4 id="411-length-required">411 Length Required</h4>
<p>Server rejected the request because the Content-Length header field is not defined and the server requires it.</p>
<h4 id="412-precondition-failed">412 Precondition Failed</h4>
<p>The client has indicated preconditions in its headers which the server does not meet.</p>
<h4 id="413-payload-too-large">413 Payload Too Large</h4>
<p>Request entity is larger than limits defined by server; the server might close the connection or return an Retry-After header field.</p>
<h4 id="414-uri-too-long">414 URI Too Long</h4>
<p>The URI requested by the client is longer than the server is willing to interpret.</p>
<h4 id="415-unsupported-media-type">415 Unsupported Media Type</h4>
<p>The media format of the requested data is not supported by the server, so the server is rejecting the request.</p>
<h4 id="416-range-not-satisfiable">416 Range Not Satisfiable</h4>
<p>The range specified by the Range header field in the request can't be fulfilled; it's possible that the range is outside the size of the target URI's data.</p>
<h4 id="417-expectation-failed">417 Expectation Failed</h4>
<p>This response code means the expectation indicated by the Expect request header field can't be met by the server.</p>
<h4 id="418-im-a-teapot">418 I'm a teapot</h4>
<p>The server refuses the attempt to brew coffee with a teapot.</p>
<h4 id="421-misdirected-request">421 Misdirected Request</h4>
<p>The request was directed at a server that is not able to produce a response. This can be sent by a server that is not configured to produce responses for the combination of scheme and authority that are included in the request URI.</p>
<h4 id="422-unprocessable-entity-webdav">422 Unprocessable Entity (WebDAV)</h4>
<p>The request was well-formed but was unable to be followed due to semantic errors.</p>
<h4 id="423-locked-webdav">423 Locked (WebDAV)</h4>
<p>The resource that is being accessed is locked.</p>
<h4 id="424-failed-dependency-webdav">424 Failed Dependency (WebDAV)</h4>
<p>The request failed due to failure of a previous request.</p>
<h4 id="425-too-early">425 Too Early</h4>
<p>Indicates that the server is unwilling to risk processing a request that might be replayed.</p>
<h4 id="426-upgrade-required">426 Upgrade Required</h4>
<p>The server refuses to perform the request using the current protocol but might be willing to do so after the client upgrades to a different protocol. The server sends an Upgrade header in a 426 response to indicate the required protocol(s).</p>
<h4 id="428-precondition-required">428 Precondition Required</h4>
<p>The origin server requires the request to be conditional. This response is intended to prevent the 'lost update' problem, where a client GETs a resource's state, modifies it, and PUTs it back to the server, when meanwhile a third party has modified the state on the server, leading to a conflict.</p>
<h4 id="429-too-many-requests">429 Too Many Requests</h4>
<p>The user has sent too many requests in a given amount of time ("rate limiting").</p>
<h4 id="431-request-header-fields-too-large">431 Request Header Fields Too Large</h4>
<p>The server is unwilling to process the request because its header fields are too large. The request may be resubmitted after reducing the size of the request header fields.</p>
<h4 id="451-unavailable-for-legal-reasons">451 Unavailable For Legal Reasons</h4>
<p>The user-agent requested a resource that cannot legally be provided, such as a web page censored by a government.</p>
<h3 id="server-error-responses">Server error responses</h3>
<h4 id="500-internal-server-error">500 Internal Server Error</h4>
<p>The server has encountered a situation it doesn't know how to handle.</p>
<h4 id="501-not-implemented">501 Not Implemented</h4>
<p>The request method is not supported by the server and cannot be handled. The only methods that servers are required to support (and therefore that must not return this code) are GET and HEAD.</p>
<h4 id="502-bad-gateway">502 Bad Gateway</h4>
<p>This error response means that the server, while working as a gateway to get a response needed to handle the request, got an invalid response.</p>
<h4 id="503-service-unavailable">503 Service Unavailable</h4>
<p>The server is not ready to handle the request. Common causes are a server that is down for maintenance or that is overloaded. Note that together with this response, a user-friendly page explaining the problem should be sent. This responses should be used for temporary conditions and the Retry-After: HTTP header should, if possible, contain the estimated time before the recovery of the service. The webmaster must also take care about the caching-related headers that are sent along with this response, as these temporary condition responses should usually not be cached.</p>
<h4 id="504-gateway-timeout">504 Gateway Timeout</h4>
<p>This error response is given when the server is acting as a gateway and cannot get a response in time.</p>
<h4 id="505-http-version-not-supported">505 HTTP Version Not Supported</h4>
<p>The HTTP version used in the request is not supported by the server.</p>
<h4 id="506-variant-also-negotiates">506 Variant Also Negotiates</h4>
<p>The server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process.</p>
<h4 id="507-insufficient-storage-webdav">507 Insufficient Storage (WebDAV)</h4>
<p>The method could not be performed on the resource because the server is unable to store the representation needed to successfully complete the request.</p>
<h4 id="508-loop-detected-webdav">508 Loop Detected (WebDAV)</h4>
<p>The server detected an infinite loop while processing the request.</p>
<h4 id="510-not-extended">510 Not Extended</h4>
<p>Further extensions to the request are required for the server to fulfill it.</p>
<h4 id="511-network-authentication-required">511 Network Authentication Required</h4>
<p>The 511 status code indicates that the client needs to authenticate to gain network access.</p>
]]></content:encoded></item><item><title><![CDATA[Simple Spring Boot with MongoDB]]></title><description><![CDATA[We are gonna make simple applications with Spring Boot and MongoDB Go to the Spring initializr chose Java 8 and next necessary dependencies When you…]]></description><link>https://mire.hashnode.dev/simple-spring-boot-with-mongodb</link><guid isPermaLink="true">https://mire.hashnode.dev/simple-spring-boot-with-mongodb</guid><category><![CDATA[Springboot]]></category><category><![CDATA[Docker]]></category><category><![CDATA[MongoDB]]></category><dc:creator><![CDATA[Mirko Djuric]]></dc:creator><pubDate>Tue, 23 Mar 2021 21:46:05 GMT</pubDate><content:encoded><![CDATA[<p>We are gonna make simple applications with Spring Boot and MongoDB</p>
<p>Go to the  <a target="_blank" href="https://start.spring.io/">Spring initializr</a> chose <code>Java 8</code> and next necessary dependencies</p>
<pre><code><span class="hljs-attribute">Spring</span> Boot <span class="hljs-number">2</span>.<span class="hljs-number">4</span>.<span class="hljs-number">4</span>
<span class="hljs-attribute">Spring</span> Web
<span class="hljs-attribute">Spring</span> Data MongoDB
</code></pre><p>When you download and import in your IDE it's time to make some code ;)</p>
<p>First, we are gonna make Person class in package <code>entity</code></p>
<pre><code><span class="hljs-keyword">package</span> com.spring.mongo.entity;


<span class="hljs-keyword">import</span> org.springframework.<span class="hljs-keyword">data</span>.<span class="hljs-keyword">annotation</span>.Id;
<span class="hljs-keyword">import</span> org.springframework.<span class="hljs-keyword">data</span>.mongodb.core.mapping.Document;


<span class="hljs-meta">@Document(collection = <span class="hljs-meta-string">"Person"</span>)</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Person</span> </span>{

    <span class="hljs-meta">@Id</span>
    <span class="hljs-keyword">private</span> String id;

    <span class="hljs-keyword">private</span> String name;


    <span class="hljs-keyword">public</span> String getId() {
        <span class="hljs-keyword">return</span> id;
    }

    <span class="hljs-keyword">public</span> void setId(String id) {
        <span class="hljs-keyword">this</span>.id = id;
    }

    <span class="hljs-keyword">public</span> String getName() {
        <span class="hljs-keyword">return</span> name;
    }

    <span class="hljs-keyword">public</span> void setName(String name) {
        <span class="hljs-keyword">this</span>.name = name;
    }
}
</code></pre><p>Next, in package <code>dao</code> we are going to make interface and DAO class</p>
<pre><code><span class="hljs-selector-tag">package</span> <span class="hljs-selector-tag">com</span><span class="hljs-selector-class">.spring</span><span class="hljs-selector-class">.mongo</span><span class="hljs-selector-class">.dao</span>;

<span class="hljs-selector-tag">import</span> <span class="hljs-selector-tag">com</span><span class="hljs-selector-class">.spring</span><span class="hljs-selector-class">.mongo</span><span class="hljs-selector-class">.entity</span><span class="hljs-selector-class">.Person</span>;
<span class="hljs-selector-tag">import</span> <span class="hljs-selector-tag">org</span><span class="hljs-selector-class">.springframework</span><span class="hljs-selector-class">.data</span><span class="hljs-selector-class">.mongodb</span><span class="hljs-selector-class">.repository</span><span class="hljs-selector-class">.MongoRepository</span>;
<span class="hljs-selector-tag">import</span> <span class="hljs-selector-tag">org</span><span class="hljs-selector-class">.springframework</span><span class="hljs-selector-class">.stereotype</span><span class="hljs-selector-class">.Repository</span>;

<span class="hljs-keyword">@Repository</span>
public interface PersonRepository extends MongoRepository&lt;Person, String&gt; {
}
</code></pre><pre><code><span class="hljs-keyword">package</span> com.spring.mongo.dao;

<span class="hljs-keyword">import</span> com.spring.mongo.entity.Person;
<span class="hljs-keyword">import</span> org.springframework.beans.factory.<span class="hljs-keyword">annotation</span>.Autowired;
<span class="hljs-keyword">import</span> org.springframework.stereotype.Component;

<span class="hljs-keyword">import</span> java.util.Collection;
<span class="hljs-keyword">import</span> java.util.NoSuchElementException;
<span class="hljs-keyword">import</span> java.util.Optional;

<span class="hljs-meta">@Component</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">PersonDAO</span> </span>{

    <span class="hljs-meta">@Autowired</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> PersonRepository personRepository;

    <span class="hljs-keyword">public</span> PersonDAO(PersonRepository personRepository) {
        <span class="hljs-keyword">this</span>.personRepository = personRepository;
    }

    <span class="hljs-keyword">public</span> Person insertPerson(Person person){
        <span class="hljs-keyword">return</span> personRepository.save(person);
    }

    <span class="hljs-keyword">public</span> Collection&lt;Person&gt; getAllPerson(){
        <span class="hljs-keyword">return</span> personRepository.findAll();
    }

    <span class="hljs-keyword">public</span> Optional&lt;Person&gt; getPersonById(String id){
        <span class="hljs-keyword">return</span> personRepository.findById(id);
    }

    <span class="hljs-keyword">public</span> Person updatePersonById(String id, Person person){
        Optional&lt;Person&gt; findPerson = personRepository.findById(id);
        Person personToBeUpdate = findPerson.<span class="hljs-keyword">get</span>();
        personToBeUpdate.setId(person.getId());
        personToBeUpdate.setName(person.getName());

        <span class="hljs-keyword">return</span> personRepository.save(personToBeUpdate);
    }

    <span class="hljs-keyword">public</span> void deletePersonById(String id){
        <span class="hljs-keyword">try</span> {
            personRepository.deleteById(id);
        }<span class="hljs-keyword">catch</span> (NoSuchElementException noSuchElementException){
            noSuchElementException.printStackTrace();
        }
    }
}
</code></pre><p>In package <code>service</code></p>
<pre><code><span class="hljs-keyword">package</span> com.spring.mongo.service;

<span class="hljs-keyword">import</span> com.spring.mongo.dao.PersonDAO;
<span class="hljs-keyword">import</span> com.spring.mongo.entity.Person;
<span class="hljs-keyword">import</span> org.springframework.beans.factory.annotation.Autowired;
<span class="hljs-keyword">import</span> org.springframework.stereotype.Service;

<span class="hljs-keyword">import</span> java.util.Collection;
<span class="hljs-keyword">import</span> java.util.Optional;

<span class="hljs-meta">@Service</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">PersonService</span> </span>{

    <span class="hljs-meta">@Autowired</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> PersonDAO personDAO;

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">PersonService</span><span class="hljs-params">(PersonDAO personDAO)</span> </span>{
        <span class="hljs-keyword">this</span>.personDAO = personDAO;
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> Person <span class="hljs-title">insertPerson</span><span class="hljs-params">(Person person)</span></span>{
        <span class="hljs-keyword">return</span> personDAO.insertPerson(person);
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> Collection&lt;Person&gt; <span class="hljs-title">getAllPerson</span><span class="hljs-params">()</span></span>{
        <span class="hljs-keyword">return</span> personDAO.getAllPerson();
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> Optional&lt;Person&gt; <span class="hljs-title">getPersonById</span><span class="hljs-params">(String id)</span></span>{
        <span class="hljs-keyword">return</span> personDAO.getPersonById(id);
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> Person <span class="hljs-title">updatePersonById</span><span class="hljs-params">(String id, Person person)</span></span>{
        <span class="hljs-keyword">return</span> personDAO.updatePersonById(id, person);
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">deletePerson</span><span class="hljs-params">(String id)</span></span>{
        personDAO.deletePersonById(id);
    }
}
</code></pre><p>And last <code>controller</code></p>
<pre><code><span class="hljs-keyword">package</span> com.spring.mongo.controller;

<span class="hljs-keyword">import</span> com.spring.mongo.entity.Person;
<span class="hljs-keyword">import</span> com.spring.mongo.service.PersonService;
<span class="hljs-keyword">import</span> org.springframework.beans.factory.<span class="hljs-keyword">annotation</span>.Autowired;
<span class="hljs-keyword">import</span> org.springframework.web.bind.<span class="hljs-keyword">annotation</span>.*;

<span class="hljs-keyword">import</span> java.util.Collection;
<span class="hljs-keyword">import</span> java.util.Optional;

<span class="hljs-meta">@RestController</span>
<span class="hljs-meta">@RequestMapping(<span class="hljs-meta-string">"/person"</span>)</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">PersonController</span> </span>{

    <span class="hljs-meta">@Autowired</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> PersonService personService;

    <span class="hljs-keyword">public</span> PersonController(PersonService personService) {
        <span class="hljs-keyword">this</span>.personService = personService;
    }

    <span class="hljs-meta">@PostMapping</span>
    <span class="hljs-keyword">public</span> Person insertPerson(<span class="hljs-meta">@RequestBody</span> Person person){
        <span class="hljs-keyword">return</span> personService.insertPerson(person);
    }

    <span class="hljs-meta">@GetMapping</span>
    <span class="hljs-keyword">public</span> Collection&lt;Person&gt; getAllPerson(){
        <span class="hljs-keyword">return</span> personService.getAllPerson();
    }

    <span class="hljs-meta">@GetMapping(path = <span class="hljs-meta-string">"{id}"</span>)</span>
    <span class="hljs-keyword">public</span> Optional&lt;Person&gt; getPersonById(<span class="hljs-meta">@PathVariable(<span class="hljs-meta-string">"id"</span>)</span> String id){
        <span class="hljs-keyword">return</span> personService.getPersonById(id);
    }

    <span class="hljs-meta">@PutMapping(path = <span class="hljs-meta-string">"/update/{id}"</span>)</span>
    <span class="hljs-keyword">public</span> Person updatePersonById(<span class="hljs-meta">@PathVariable</span> String id, <span class="hljs-meta">@RequestBody</span> Person person){
        <span class="hljs-keyword">return</span> personService.updatePersonById(id, person);
    }

    <span class="hljs-meta">@DeleteMapping(path = <span class="hljs-meta-string">"/delete/{id}"</span>)</span>
    <span class="hljs-keyword">public</span> void deletePerson(<span class="hljs-meta">@PathVariable</span> String id){
         personService.deletePerson(id);
    }

}
</code></pre><p>In applications.properties add database name
<code>spring.data.mongodb.database=springbootwithmongo</code></p>
<p>Now run mongo in docker. Go to the project folder and run next command 
<code>docker-compose up -d</code>. If you don't know how, please read my  <a target="_blank" href="https://mire.hashnode.dev/docker-container-deployment-with-mongodb">article</a> </p>
<p>We will post few persons</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616506122059/ITVFLfxvQY.png" alt="03 post.png" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616506131702/C0Mnj8kWD.png" alt="04 post.png" /></p>
<p>Now we are gonna see all persons that are saved</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616506225599/EFFZI3bk3.png" alt="05 get.png" /></p>
<p>Now, we are gonna update one person</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616506260227/-RIFzQRrT.png" alt="05 put.png" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616506278572/poelmVJ2-.png" alt="07 get.png" /></p>
<p>Delete one person</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616506356320/8YpFMU5CI.png" alt="08 delete.png" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616506362097/Apznat9IW.png" alt="09 get.png" /></p>
<p>As you can see, it takes few clicks and few lines of code to make a simple application with Spring Boot and Mongo in Docker</p>
<p>Here is  <a target="_blank" href="https://github.com/mirkomiredjuric/SpringBootWithMongoDB">link</a>  to github.</p>
<h2 id="thank-you-for-reading">Thank you for reading</h2>
<h1 id="if-you-like-what-you-read-and-want-to-see-more-please-support-me-with-coffee-or-a-beerhttpswwwbuymeacoffeecommire">If you like what you read and want to see more, please support me with  <a target="_blank" href="https://www.buymeacoffee.com/mire">coffee or a beer</a>  ;)</h1>
]]></content:encoded></item><item><title><![CDATA[Docker container deployment with MongoDB]]></title><description><![CDATA[Go to the and search for mongodb. When you open it, on top right side you will see docker command to pull image Copy that command in terminal and run it]]></description><link>https://mire.hashnode.dev/docker-container-deployment-with-mongodb</link><guid isPermaLink="true">https://mire.hashnode.dev/docker-container-deployment-with-mongodb</guid><category><![CDATA[Docker]]></category><category><![CDATA[MongoDB]]></category><dc:creator><![CDATA[Mirko Djuric]]></dc:creator><pubDate>Sun, 21 Mar 2021 16:06:53 GMT</pubDate><content:encoded><![CDATA[<h3 id="downloading-mongodb-docker-image">Downloading MongoDB Docker image</h3>
<p>Go to the https://hub.docker.com/ and search for mongodb. </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616339513677/G5VYNXwBf.png" alt="01.png" /></p>
<p>When you open it, on top right side you will see docker command to pull image</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616339575085/EtzoN2UCE.png" alt="02.png" /></p>
<p>Copy that command in terminal and run it</p>
<p><code>docker pull mongo</code></p>
<h3 id="verify-that-you-have-download-mongodb-docker-image-on-your-machine">Verify that you have download MongoDB docker image on your machine</h3>
<p><code>docker images</code></p>
<p>and you will something like this</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616339875380/RwrMrDsRo.png" alt="03.png" /></p>
<h3 id="deploy-mongo-image-as-a-container">Deploy mongo image as a container</h3>
<p><code>docker run -d -p 27017:27017 --name mongodb mongo</code></p>
<p>and after that when you run <code>docker ps</code> you will see something like this</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616340390019/eYeW96HxJ.png" alt="04.png" /></p>
<p>MongoDB container with name "mongodb", ports to be exposed and other</p>
<h3 id="getting-inside-of-mongodb-docker-container">Getting inside of MongoDB Docker container</h3>
<p><code>docker exec -it mongodb bash</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616340674339/ivQGgrPp-.png" alt="05.png" /></p>
<p>we are now connected with our container named <code>mongodb</code> </p>
<p>To launch mongodb shell, type next command</p>
<p><code>mongo</code></p>
<p>and you will see something like this</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616340999300/gs9q6JJ75.png" alt="06.png" /></p>
<p>If you don't know mongo commands or you are rookie like me, you can find some useful commands on  <a target="_blank" href="Link">https://docs.mongodb.com/manual/reference/mongo-shell/ </a> </p>
<h3 id="create-database-create-collection-and-add-some-data">Create database, create collection and add some data</h3>
<p>First lets check all dbs in mongo, simply type <code>show dbs</code> in terminal</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616341596262/RTXf72oIh.png" alt="07.png" /></p>
<p>Create new database with this command <code>use dbName</code> like i did 'use miredeveloper`</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616341668733/709hpRlNI.png" alt="08.png" /></p>
<p>Now we are gonna add new collections with some data to our db</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616341877599/kS6pt_Jh1.png" alt="09.png" /></p>
<p>We can see all collections in our database, just type <code>show collections</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616341944087/3E6nr10F1.png" alt="10.png" /></p>
<p>And yes, we can see all data in some specific collection</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1616341986770/0s0NM6E-4.png" alt="11.png" /></p>
<h2 id="thank-you-for-reading">Thank you for reading</h2>
<h1 id="if-you-like-what-you-read-and-want-to-see-more-please-support-me-with-coffee-or-a-beerhttpswwwbuymeacoffeecommire">If you like what you read and want to see more, please support me with  <a target="_blank" href="https://www.buymeacoffee.com/mire">coffee or a beer</a>  ;)</h1>
]]></content:encoded></item></channel></rss>