Spring add references to different projects - java

Newbie question: I have different projects that im doing in STS, all opened. For example i have myproject_mvc and myproject_datamodel.
In myproject_mvc are the views and controllers.
In myproject_datamodel are the class of the Model like: Person, Car, etc.
the project_datamodel is used in other projects too. So i want to add a reference and use it like if that class where in myproject_mvc.
I added doing right click over myproject_mvc Build Path/Configure Build Path/Projects and i added the porject there, but when i run the application i recieve this error message:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: solvian_datamodel/Vehicle
Maybe i have to register that dependency in pom.xml or other file that i dont know.

You need to configure Web Deployment Assembly in STS.
Try following:
Go to myproject_mvc's properties -> Deployment Assembly.
Click Add button.
Add dependency projects.
Hope this helps.

Related

Occasional BeanCreationException in Java Spring Boot project built with Gradle

Sometimes I get a BeanCreationException when starting a Java Spring Boot single-JAR application built by Gradle. My investigations show that it depends on the JAR file and how it has been built by Gradle. Most often (but not always) I see the exception when I build the project on a Linux system. But I have never reproduced the issue with a JAR built on Windows or when running from IntelliJ Idea.
I tried to compare the content of a working JAR with the JAR throwing the exception - all the *.class files (including meta and resources) were binary equal, the only difference was in the order the files were stored in the JAR/ZIP archive. I also tried to unpack the failing JAR on Windows and just repack it into a new JAR file (using 7-zip) - the application started without any exceptions. This weird workaround solved the issue, but it's not something I'd like to do after each build on a linux machine.
The exception suggests to check circular references, so I tried replacing #Autowired properties with #Autowired bean constructors to help me to find the problem but that didn't help. The stacktrace does not mention any of my classes, so I don't know what bean could be responsible for the issue. And because of the fact the issue happens only sometimes and is solvable by repacking the JAR file, I'm not sure there are any circular references anyway.
Could you please help me? Any advice or suggestion is welcomed.
JDK: openjdk 8u262
Gradle version 5.6
Spring boot 2.3.1
Exception message:
BeanCreationException: Error creating bean with name 'webConfig':
Invocation of init method failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource
[org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]:
Unsatisfied dependency expressed through method 'requestMappingHandlerAdapter' parameter 0;
nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException:
Error creating bean with name 'mvcContentNegotiationManager':
Requested bean is currently in creation: Is there an unresolvable circular reference?
By default, Spring manages itself bean's lifecycle and then, arranges their initialization order during the startup.
Here a full example of usage #DependsOn annotation to order the bean instanciation.
You can also found more detail in the official Spring documentation

SAP Hybris Assisted Service Module (ASM) - can't generate component

I've installed and tested ASM on my localhost successfully (we use Hybris 1811). Then I wanted to transfer it on our dev server (actually it was only changes in localextensions.xml and regenerated extensionsinfo.xml), so in extensionsinfo.xml of my storefront there is the addon registrated like this:
<requires-extension name="assistedservicestorefront "/>
But it doesn't generate files in views:
[DefaultCMSComponentRendererRegistry] Error processing component tag. currentComponent [AssistedServiceComponentModel (8796814312508#2)] exception:
File [/WEB-INF/views/responsive/cms/assistedservicecomponent.jsp] not found
I've imported the same .impex file as in the manual for installing ASM (from help.hybris.com) and as on the localhost (cms-content.impex to include component and Jsp).
Even though I run update in HAC, I tried to sync content catalog. I checked extensions in HAC, it contains same ASM extensions as on my local machine: assistedservicefacades, assistedserviceservices, assistedservicestorefront.
When I checked the backoffice, the component with that ID is really there and it's in online catalog.
How do I make those files to generate? Or should I somehow override them with my custom views? But I think it would be bad approach.
UPDATE: I also tried to add this entry to project.properties of my storefront:
sikob2cstorefront.additionalWebSpringConfigs.assistedservicestorefront=classpath\:/assistedservicestorefront/web/spring/assistedservicestorefront-web-spring.xml
but then I got the error loading beans:
Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultStorefrontTenantDefaultFilterChainList': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'AssistedservicestorefrontFilterListMergeDirective' defined in class path resource [assistedservicestorefront/web/spring/assistedservicestorefront-web-spring.xml]: Cannot resolve reference to bean 'assistedServiceFilter' while setting add; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'assistedServiceFilter' defined in class path resource [assistedservicestorefront/web/spring/assistedservicestorefront-web-spring.xml]: Cannot resolve reference to bean 'assistedServicePathRestrictionEvaluator' while setting bean property 'assistedServicePathRestrictionEvaluator'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'assistedServicePathRestrictionEvaluator' available
# Install assistedservicestorefront
# Replace Mystorefront with your storefront extension name
ant addoninstall -Daddonnames="assistedservicestorefront" -DaddonStorefront.yacceleratorstorefront="Mystorefront"
I think you have missed installing the assistedservicestorefront addon or if you've already installed then check whether below changes have taken place on your server.
addoninstall command makes below changes
Adds assistedservicestorefront into extensioninfo.xml of your storefront extension
like
<requires-extension name="assistedservicestorefront "/>
Generate a new project.properties file from project.properties.template inside assistedservicestorefront, which has following entries.
Replace yacceleratorstorefront with your storefront extension name in the below property.
#Specifies the location of the spring context file added automatically to the global platform application context.
assistedservicestorefront.application-context=assistedservicestorefront-spring.xml
yacceleratorstorefront.additionalWebSpringConfigs.assistedservicestorefront=classpath:/assistedservicestorefront/web/spring/assistedservicestorefront-web-spring.xml
assistedservicestorefront.javascript.paths.mobile=/responsive/common/js/assistedservicestorefront.js;/responsive/common/js/jquery.tablesorter.pager.js;/responsive/common/js/jquery.tablesorter.min.js;/responsive/common/js/Chart.min.js;/responsive/common/js/asm.storefinder.js
assistedservicestorefront.javascript.paths.responsive=/responsive/common/js/assistedservicestorefront.js;/responsive/common/js/jquery.tablesorter.pager.js;/responsive/common/js/jquery.tablesorter.min.js;/responsive/common/js/Chart.min.js;/responsive/common/js/asm.storefinder.js
assistedservicestorefront.css.paths.mobile=/responsive/common/css/assistedservicestorefront.css;/responsive/common/css/storeFinder.css;/responsive/common/css/customer360.css
assistedservicestorefront.css.paths.responsive=/responsive/common/css/assistedservicestorefront.css;/responsive/common/css/storeFinder.css;/responsive/common/css/customer360.css
assistedservicestorefront.redirect.customer_and_cart=/cart
assistedservicestorefront.redirect.customer_only=/my-account
assistedservicestorefront.redirect.error=/
assistedservicestorefront.redirect.order=/my-account/order/%s
assistedservicestorefront.deeplink.link=/assisted-service/emulate
cscokpit.assistedservice.deeplink=true
assistedservicestorefront.profile.cookie.name=profile.tracking.pause
#AIF AJAX call timeout in milliseconds
assistedservicestorefront.aif.timeout=7000
So if you don't want to run addoninstall command in each environment then you can manually do these two changes. You can refer to the generated project.properties file inside your addon and copy all those properties to your storefront's project.properties or local.properteis file and commit the changes.

When I add Actuator dependency it gives UnsatisfiedDependencyException

I have a springboot application. When I add spring-boot-starter-actuator dependency to my pom it gives UnsatisfiedDependencyException.
Without this dependency, application is running. When I put it, application not running.
Can anyone provide a solution for this?
Error:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'servoMetricCollector' defined in class path resource

initializing AWS with Springboot

I am trying to initialize and build a Springboot Application that uses AWS dependencies on Net Beans, however, I am having a problem building the project. After resolving the errors after creating the project I am getting an error when I try to build. The message I get is
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cloud.aws.context.support.io.ResourceLoaderBeanPostProcessor#0': Cannot resolve reference to bean 'amazonS3' while setting constructor argument;
I found some previous answers saying to put cloud.aws.stack.auto=false in my application.properties file, however, I seem to be getting the same problem after I clean and build again.
If you are building/ testing or running locally (as opposed to EC2) then you need to have a region property such as in application.properties assuming you use the default profile for build and test.
cloud.aws.region.static=us-east-1

How to build the war files for oAuth2-sample project?

I cloned the project here https://github.com/OhadR/oAuth2-sample
Set appropriate version for parent in pom.xml of all 3 projects oauth2-client, oauth2-auth-server, resource-sercer to
<version>1.6.2-SNAPSHOT</version>
I added the 3 projects to modules section in auth-parent. I built war files using mvn install.
<modules>
<module>auth-common</module>
<module>common-crypto</module>
<module>authentication-flows</module>
<module>oauth2-auth-server</module>
<module>oauth2-client</module>
<module>oauth2-resource-server</module>
</modules>
I put the 3 generate war file in jetty/webapps. Client and Resource-server seem to load fine but oauth2-auth-server doesnt. At localhost:8080 I get UNAVAILABLE for oauth2-auth-server.
I tried debugging by adding maven-jetty plugin and mvn jetty:run for oauth2-auth-server. But I get
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/spring-servlet.xml]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'authenticationSuccessHandler' for bean class [com.ohadr.auth_flows.core.AuthenticationSuccessHandler] conflicts with existing, non-compatible bean definition of same name and class [com.ohadr.oauth_srv.web.OhadAuthenticationSuccessHandler]
Not sure I see the problem - did you try build it from the main directory, by using maven command "mvn clean install"?
Maven will then build all sub-modules, which are common-crypto and authentication-flows.
My oAuth-Sample project is in use as an oAuth example as well as "authentication-flows" logic.
Do you build this oAuth-sample for oAuth-sample, or for "authentication-flows"?
Hope that helps (and sorry about the delay)

Categories