Saturday, January 30, 2021

Why can't you use @Autowired with static fields?

Because when the class loader loads the static values, the Spring context is not yet necessarily loaded. So the class loader won't properly inject the static fields in the bean and will fail.

https://stackoverflow.com/questions/10938529/why-cant-we-autowire-static-fields-in-spring/21875258#21875258


Its basically an "ANTI-PATTERN", Still we have a hack to work around this limitation, Here it is.

https://stackoverflow.com/questions/1018797/can-you-use-autowired-with-static-fields/5991240#5991240

@Component("NewClass")
public class NewClass{
    private static SomeThing someThing;

    @Autowired
    public void setSomeThing(SomeThing someThing){
        NewClass.someThing = someThing;
    }
}

URI - Filepath vs Spring Filepath Convention

 file:///C:/Path

https://en.wikipedia.org/wiki/File_URI_scheme

https://www.marcobehler.com/guides/java-files

Format[edit]

A file URI takes the form of

file://host/path

where host is the fully qualified domain name of the system on which the path is accessible, and path is a hierarchical directory path of the form directory/directory/.../name. If host is omitted, it is taken to be "localhost", the machine from which the URL is being interpreted. Note that when omitting host, the slash is not omitted (while "file:///foo.txt" is valid, "file://foo.txt" is not, although some interpreters manage to handle the latter).

RFC 3986 includes additional information about the treatment of ".." and "." segments in URIs.

How many slashes?[edit]

  • The // after the file: denotes that either a hostname or the literal term localhost will follow,[2] although this part may be omitted entirely, or may contain an empty hostname.[3]
  • The single slash between host and path denotes the start of the local-path part of the URI and must be present.[4]
  • A valid file URI must therefore begin with either file:/pathfile:///path or file://hostname/path.
  • file://path (i.e. two slashes, without a hostname) is never correct, but is often used.
  • Further slashes in path separate directory names in a hierarchical system of directories and subdirectories. In this usage, the slash is a general, system-independent way of separating the parts, and in a particular host system it might be used as such in any pathname (as in Unix systems).

Spring Filepath just has prefix "file:"
  • -DjunkCharCleanup="file:C:/Users/703250313/Desktop/ExternalConfig/junk-char-cleanup"
URI Filepath
  • -DsamlMetaDataFilepath="file:///C:/Users/703250313/Desktop/ExternalConfig/metadata.xml"

Spring Bean: Is autowired attribute initialised before constructor?

https://stackoverflow.com/questions/26230493/spring-bean-is-autowired-attribute-initialised-before-constructor


  1. First Constructor is called
  2. Then Spring Bean is initialized

Unicode to Character - How ?

https://www.branah.com/unicode-converter

Maven to Spring Application.Properties - Profile

 #server.port=8081

spring.profiles.active=@activatedProperties@

https://www.petrikainulainen.net/programming/tips-and-tricks/creating-profile-specific-configuration-files-with-maven/


<profiles>

<!-- DEV Build -->

<profile>

<id>DEV1</id>

<properties>

<activatedProperties>DEV1</activatedProperties>

</properties>

</profile>


<!-- AZURE Build -->

<profile>

<id>QA</id>

<properties>

<activatedProperties>QA</activatedProperties>

</properties>

</profile>

@Service classes are being created twice when the application starts.

https://stackoverflow.com/questions/4333390/service-are-constructed-twice


You're doing two separate component-scans over the same base-package. Remove one of them.
Make the following changes

myapp-config.xml

<!-- Load everything except @Controllers -->
<context:component-scan base-package="com.myapp">
    <context:exclude-filter expression="org.springframework.stereotype.Controller"
        type="annotation"/>
</context:component-scan>

myapp-servlet.xml

<!-- Load @Controllers only -->
<context:component-scan base-package="com.myapp" use-default-filters="false">
    <context:include-filter expression="org.springframework.stereotype.Controller" 
        type="annotation"/>
</context:component-scan>

CURL Headers Base64 Authorization

curl --location --request POST 'https://test.salesforce.com/services/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Cookie: BrowserId=4jzphkElEeu76TsJSxG4Tw' \
--data-urlencode 'client_id='a2rtyoi.k9iosdgh.b6rbmnb' \
--data-urlencode 'client_secret=23987590772833' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'username=foo@bar.com' \
--data-urlencode 'password=Red1$Apple'

curl --location --request GET 'http://10.102.13.101:8086' --header 'Authorization: Basic base64[username:Password]
curl --location --request GET 'http://AZ-CVS-LI-RE-02:8086' --header 
'Authorization: Basic U2hlZXRhbFM6ZWYxNTE1NWY3YTJjOGNiZWIyYjM3N2Q0NmQ2ZWRkYzkzOTg3NjljYTlhMzUyOTkwZDFhYjI1MzcxNDAyNzJiYQ=='

Azure - Pipeline - Add Approver for Stage

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/approvals?view=azure-devops&tabs=check-pass