<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>emulator &#8211; CodePills.com</title>
	<atom:link href="https://codepills.com/tag/emulator/feed/" rel="self" type="application/rss+xml" />
	<link>https://codepills.com</link>
	<description>Helping you make a better code</description>
	<lastBuildDate>Thu, 17 Jun 2021 12:31:14 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>How to connect Azure Cosmos DB Emulator with Spring Boot app at Windows</title>
		<link>https://codepills.com/how-to-connect-azure-cosmos-db-emulator-with-spring-boot-app-at-windows/</link>
					<comments>https://codepills.com/how-to-connect-azure-cosmos-db-emulator-with-spring-boot-app-at-windows/#respond</comments>
		
		<dc:creator><![CDATA[Andrej Buday]]></dc:creator>
		<pubDate>Fri, 21 Feb 2020 13:58:46 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[certificate]]></category>
		<category><![CDATA[cmd]]></category>
		<category><![CDATA[CosmosDB]]></category>
		<category><![CDATA[emulator]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JDK]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[windows]]></category>
		<guid isPermaLink="false">https://codepills.com/?p=1060</guid>

					<description><![CDATA[In this article, we look at installing Azure Cosmos DB Emulator on your Windows machine and using the Azure Cosmos DB Emulator for local development of our Spring Boot application. <a href="https://codepills.com/how-to-connect-azure-cosmos-db-emulator-with-spring-boot-app-at-windows/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>This article will look at how to install Azure Cosmos DB Emulator on your Windows machine and how to use the Azure Cosmos DB Emulator for the local development of our Spring Boot application.</p>
<p><span id="more-1060"></span></p>
<h2>How to install Azure CosmosDB Emulator</h2>
<p>First of all, we need to install Azure CosmosDB Emulator locally. Go to <a href="https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator#installation" title="How to install Cosmos DB" rel="nofollow noopener" target="_blank">https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator#installation</a>, download the windows installation package and install <strong>Azure Cosmos DB Emulator</strong>.</p>
<p>When installing Azure Cosmos DB Emulator passed successfully on your Windows machine, start the emulator (if it did not start automatically).</p>
<p>If it is already running you can find it minimized in the system hidden in the running application system and either click <strong>Open Data Explorer &#8230;</strong> or visit <a href="https://localhost:8081/_explorer/index.html" title="local address of Azure Cosmos DB Emulator" rel="nofollow noopener" target="_blank">https://localhost:8081/_explorer/index.html</a> page. You can now get finally into the Azure CosmosDB Emulator.</p>
<h2>Exporting security certificates</h2>
<p>Azure Cosmos DB Emulator uses a secure connection with your application. We need to extract and register your certificate for communication with the emulator.</p>
<p>Let’s type &#8220;Manage user certificates&#8221; into Windows Start console or open Windows Certificate Manager (running certlm.msc in the run prompt). Go to Personal->Certificates folder and export certificate with <strong>DocumentDbEmulatorCertificate</strong> name. The whole tutorial how to do it can be found at <a href="https://docs.microsoft.com/bs-latn-ba/azure/cosmos-db/local-emulator-export-ssl-certificates#how-to-export-the-azure-cosmos-db-ssl-certificate" title="How to export Azure Cosmos DB SSL certificate" rel="nofollow noopener" target="_blank">Microsoft Azure website</a> explaining how to export the Azure Cosmos DB SSL certificate.</p>
<p>You can name your file when exporting arbitrary. However, we will name it for our example <strong>documentdbemulatorcert.cer</strong>.</p>
<p>Now when I have extracted the SSL certificate, I need to upload it into the correct Java SDK location.</p>
<p>Check which version of Java do you use in your project. In IntelliJ idea you can use either keyword shortcut [ctrl] + [shift] + [alt] + [s] or go to File->Project Structure->SDKs and check which version your Spring Boot application uses or where SDK is located.</p>
<p>Copy certificate into the Java SDK directory. It should be copied into the <strong>%JAVA_HOME%/jre/lib/security</strong> location.</p>
<p>If you use OpenJDK, OpenJDK does not contain <strong>jre</strong> folder. Just copy it into <strong>%JAVA_HOME%/lib/security</strong> location.</p>
<h2>Registering certificate</h2>
<p>The nearly last thing we need to do is to register the certificate into the system.</p>
<p>We need to open the Windows Command prompt as an administrator and navigate at JDK&#8217;s folder at jdk\jre\lib\security.</p>
<p><strong>Hint</strong>: A little hint if you are more familiar with Linux based systems than Windows. If you open a folder in Windows, copy the path to the folder and place it into quotation marks in the command prompt. Executing the command changes the directory instantly.</p>
<p>Then, upon the folder, we need just to run the following command to register the certificate into the keystore on your system:</p>
<pre><code class="language-bash">keytool -keystore cacerts -importcert -alias documentdbemulator -file documentdbemulatorcert.cer</code></pre>
<p><strong>Hint</strong>: Keytool is a tool located in your Java installation, so you need to have jdk/bin on your PATH for this to work.</p>
<p>If you need a hint with registration, check this tutorial at <a href="https://docs.microsoft.com/en-us/azure/java/java-sdk-add-certificate-ca-store?view=azure-java-stable#to-add-a-root-certificate-to-the-cacerts-store" title="How to add a root certificate to the cacerts store" rel="nofollow noopener" target="_blank">Microsoft Azure website</a> where you learn how to add a root certificate to the certification authority certificates storage. However instead of <strong>bc2025.cer</strong> name in tutorial use name of your certificate.</p>
<p>Otherwise, when the prompt asks for a password, type your password. More likely you didn&#8217;t change it, so default password is <strong><i>changeit</i></strong>. Following, you get a question, if you trust this certificate. Answer it simply <strong>yes</strong>.</p>
<p>That is it. The certificate is registered, and Azure Cosmos DB Emulator should be now created securely and with ease.</p>
<h2>Using emulator with local Spring Boot app development</h2>
<p>And all we need to do now is just run the Spring Boot application. If you implemented a connection to Cosmos DB and registered connection properties to <code>application.properties</code> or <code>application.yml</code> you can successfully run the application.</p>
<pre><code class="language-yaml">azure:
   cosmosdb:
    uri: https://localhost:8081
    key: VERY_LONG_KEY
    database: YOUR_DB_NAME</code></pre>
<p>To fill up <code>application.yml</code> you will need to implement your own data:</p>
<p>You can find VERY_LONG_KEY in your Azure Cosmos DB Emulator Data Explorer under the <i>Quick start</i> tab.</p>
<p>And all we need to do now is just run the Spring Boot application. If you check now Data Explorer under <i>Explorer</i> tab, you can find now your database with all the defined structures.</p>
<h2>Troubleshooting</h2>
<p>In case you already successfully installed the Azure CosmosDB Emulator and you want to restart the database, you have an option to reset data. Data reset comes handy when you get an authentication issue over HTTPS with your Azure CosmosDB certificate on the application run.</p>
<p>Pick up &#8220;Reset data&#8221; from the Azure CosmosDB Emulator mini-panel dialogue window from your start button. Operation is not reversible; it will clean up all your caches and the internal state of the Azure CosmosDB Emulator database and reset the certificate.</p>
<p>Then it would be best if you continued extracting the certificate from the list of certificates according to the description in Exporting Security Certificates. However, before registering the certificate back to Java keytool, you need to remove the old alias on the certificate with a command like this:</p>
<pre><code class="language-bash">keytool -delete -alias documentdbemulator -keystore cacerts -storepass changeit</code></pre>
<p><strong>Notes</strong>: behind <code>-alias</code> you place the name of the certificate, <code>-keystore</code> is the name of a file containing the certificates and behind <code>-storepass</code> is your password (default is <i>changeit</i>).</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codepills.com/how-to-connect-azure-cosmos-db-emulator-with-spring-boot-app-at-windows/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
