Posts

Showing posts with the label Spring

'jasypt.encryptor.password' or one of ['jasypt.encryptor.privateKeyString', 'jasypt.encryptor.privateKeyLocation'] must be provided for Password-based or Asymmetric encryption

Image
      Intellij spring boot build failing not seeing the jasypt password. The same is working fine with the normal startup and is also working with mvn command.     Caused by: org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'spring.security-org.springframework.boot.autoconfigure.security.SecurityProperties': Could not bind properties to 'SecurityProperties' : prefix=spring.security, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.security.user.password' to java.lang.String Caused by: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.security.user.password' to java.lang.String Caused by: org.springframework.cache.Cache$ValueRetrievalException: Value for key 'spring.security.user.password' could not be load...

The matching wildcard is strict, but no declaration can be found for element 'jaxrs:client'.

The Answer is in the Migration Guide 3.0 Migration Guide JAX-RS JAX-RS 2.0 has been completely implemented. JAX-RS WADL auto-generation code has been moved to a new cxf-rt-rs-service-description module. JAX-RS 2.0 Client API and CXF specific WebClient and Proxy client code is now available in a new cxf-rt-rs-client module. Important: the namespace for jaxrs:client elements has changed from "http://cxf.apache.org/jaxrs" to "http://cxf.apache.org/jaxrs-client " CXF RequestHandler and ResponseHandler filters have been removed, please use JAX-RS 2.0 ContainerRequestFilter and ContainerResponseFilter and also WriterInterceptor and ReaderInterceptor when needed. CXF JAX-RS Form extension has been dropped, please use JAX-RS 2.0 Form. CXF JAX-RS ParameterHandler has been dropped, please use JAX-RS 2.0 ParamConverterProvider. javax.annotation.Resource annotation can no longer be used to annotate JAX-RS context properties. Only javax.ws.rs.core.Context annotat...

Field or property 'jobParameters' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - Spring Batch

This Error happens when you are trying to retrieve a Job Execution parameter and inject it into a Bean. The bean can be anything a Task let, or a StatmentSetter the error can happen. E.g Implementation <bean id = "flatFileItemReader" scope="step" class="org.springframework.batch.item.file.FlatFileItemReader"> <property name = "resource" value = "#{jobParameters[input.file.name]}" /> </bean> The error is because of the Scope parameter missing Using a scope of  Step  is required in order to use late binding since the bean cannot actually be instantiated until the  Step  starts, which allows the attributes to be found. Because it is not part of the Spring container by default, the scope must be added explicitly. Check out the Documentation here ..  http://docs.spring.io/spring-batch/reference/html/configureStep.html#step-scope

Autowiring a static variable using Spring

Yes, This sounds wrong and should never try to do it in a proper design (According to me). With the above disclaimer, Might run into such a case where we need to do this kind of thing, you are at the right blog. There are 2 ways to do it i guess, i have the simple working way jotted here. Lets get started Consider the class @Component public class Foo { private static ObjectA objectA; // Static variable to be used in static method in class @Autowired ObjectA autowiredObjectA; // Orginal bean that is autowired @postConstruct public void init() {   Foo.objectA=this.autowiredObjectA; // So this method is responsible for handing out the bean after                                                                     the class is constructed and autowired by the spring         ...

Web app root system property already set to different value: 'webapp.root'

<context-param>     <param-name>webAppRootKey</param-name>     <param-value>{project name and version}</param-value>    </context-param> Add this to Web.xml and this will fix the issue. Replace the value with project name and version number. Happy Coding.

Illegal character(s) in message header value

Recently was trying to consume a Rest Web Service by passing AES256 encrypted values in header Params and hit the above exception. java.lang.IllegalArgumentException: Illegal character(s) in message header value: After a little bit of resaerch i found that it is a bug with java while using BASE64 Encoded String.If the string length exceeds 76 characters, the Base64Encoder adds a "\n" character. While trying to sent it in header it fails complaining about the "\n" in the Base64 encoded string. This is actually a bug with JAVA http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6459815 The fix is String encodeMe = m_username + ":" + m_sToken; BASE64Encoder encoder = new BASE64Encoder(); String base64Encoded = encoder.encode(encodeMe.getBytes()); //!Important! - Get rid of any newline characters erroneously // added by the Base64Encoder base64Encoded = base64Encoded.replaceAll(...

Why Spring Over EJB?

1. EJB is Complicated - To implement any functionality we need to touch at least 4 files business Interface,Home Interface,Beans and Deployment Descriptor.However with Spring it works on POJO and can use AOP for further services. 2. EJB is Invasive - In order to implement an interface in EJB we need to use Javax.ejb interface.There is a tight coupling with the EJB and code always requires an EJB container for it to work.however in the case of Spring there is no such direct dependancy on Spring code. 3. Entity Ejb's are not as mature as the ORM frameworks avaliable like Hibernate etc.Spring provides an excellent integration with these ORM frameworks.

Spring AOP

An Enterprise Application has many components and each performing its own function.Some times one component has to perform the function of another like logging,Security,transaction Management all goes into different component to manage.These are called Cross cutting Concerns as they cut into other functionality. AOP Helps us to make these functionalists a different layer and these layer can be applied declaratively.So we add an Aspect to a functionality whose responsibilty is to do its job. The Acegi security system uses Spring’s AOP support as the foundation of a framework that adds declarative security to Spring-enabled applications