Wednesday, 19 April 2017

Spring Bean Injection without MVC and DispatcherServlet

Basically there is a difference between the type of context initialized for the spring container in terms of web application. If there is a scenario where you cannoto use the spring mvc architecture , there are 2 ways how you can inject the bean in different classes

1) Below Code Example
2) Use Springs AutoWiring mechanism in the servlet class.

1) Create a simple resttemplate bean in the applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">


    <!-- Application Context Init -->
    <beans:bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
      
    </beans:bean>
     


2) Load a spring bean file that is stored within your web inf  and set it to the serveltContext to make it application wide. May be you can invoke this within your application listener to invoke it only while deployment

String filePath = "D:\\workspace\\PROJECTX\\WebContent\\WEB-INF\\spring\\applicationContext.xml";
    ApplicationContext ctx = new FileSystemXmlApplicationContext(filePath);
    sce.getServletContext().setAttribute("ctx", ctx);

3) Use the bean in your method

        ApplicationContext ctx =  (ApplicationContext)  httpRequest.getSession().getServletContext().getAttribute("ctx");
        RestTemplate restTemplate = ctx.getBean(RestTemplate.class);
        ResponseEntity<String> response= restTemplate.getForEntity("https://callMyRestAPI/user",   String.class );


4) jars

Sunday, 16 April 2017

Maven Hot Deployment Plugin on Weblogic 12c

1) Install jar 
mvn install:install-file -DpomFile=oracle-maven-sync-12.2.1.pom -Dfile=oracle-maven-sync-12.2.1.jar
path:- D:\installs\fmw_12.2.1.1.0_wls_quick_Disk1_1of1\wls12210\oracle_common\plugins\maven\com\oracle\maven\oracle-maven-sync\12.2.1

2) Sync Local Repo - (Requires Internet)
mvn com.oracle.maven:oracle-maven-sync:push -DoracleHome=D:\installs\fmw_12.2.1.1.0_wls_quick_Disk1_1of1\wls12210\ -Doracle-maven-sync.testingOnly=false

3) Add Plugin to profile within pom.xml


<build>
        <plugins>
            <plugin>
        <groupId>com.oracle.weblogic</groupId>
        <artifactId>weblogic-maven-plugin</artifactId>
        <version>12.2.1-1-0</version>
        <configuration>
            <adminurl>t3://localhost:7001</adminurl>
            <user>weblogic</user>
            <password>admin123</password>
            <upload>true</upload>
            <!-- <targets>myServer</targets> -->
            <action>deploy</action>
            <remote>false</remote>
            <verbose>true</verbose>
            <source>D:\workspace\YOLO\target</source>
            <name>YOLO</name>
        </configuration>
        <executions>
            <execution>
                <phase>install</phase>
                <goals>
                    <goal>deploy</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
        </plugins>
    </build>


Article to follow :- https://ruleoftech.com/2014/using-the-weblogic-12c-maven-plug-in-for-deployment

AWS Certificate Manager - Import Certificate

How to import a certificate. Use Key Store Explorer to open the cert and export keypair in PEM format  This will save a file cert.pem. Make ...