In Spring I can create a bean from an inner class thus:
<bean id="exampleInnerBean" class="my.package.Class$InnerClass" />
But in Blueprint this doesn't work, I get a SAXParseException:
cvc-datatype-valid.1.2.1: 'my.package.Class$InnerClass' is not a valid value for 'NCName'.
Any ideas what I'm doing wrong / what syntax I should be using / if this is even possible?
If it helps / matters, I'm installing a bundle containing the above bean into JBoss Fuse 6.0.0.
Many thanks
I was able to just use the same syntax as in Java:
<bean id="exampleInnerBean" class="my.package.Clazz.InnerClass" />
The only problem I faced was because I am using the Maven Bundle plugin... the plugin assumed that my.package.Clazz was a package and therefore added it to the list of imported packages for my bundle. This is simply fixed by adding the following to the plugin <configuration><instructions> tag in the POM:
<Import-Package>!my.package.Clazz,*</Import-Package>
This stops the plugin adding my.package.Clazz to the list of imported packages for my bundle and everything just works.
Related
I have been given a Java Spring application to containerize. I am using a Tomcat8/Java8 base image. When it boots, it fails to deploy with the following error:
Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'controller3P' for bean class [com.******.******.brand3P.controller.Controller3P] conflicts with existing, non-compatible bean definition of same name and class [com.******.******.Brand3P.controller.Controller3P]
The problem here seems to that Spring is finding 2 conflicting classes, differentiated by "brand3P" and "Brand3P".
However, in the source code, I can find no reference to a class "Brand3P", only a class "brand3P".
Can anyone explain what Spring is doing here?
(Be nice, I'm Ops, not Dev)
Package name should be all lower cased, checkout here oracle doc
Package name is not included in spring definition name.
My guess is someone changed the package name in Git, because git is by default case insensitive, so you will run into this situation, if it is this case, remove the file and create it again will fix this problem.
Hi Ops, please work with Devs together ;)
Turns out it was an issue with the build in Jenkins. The code had changed (Brand3P -> brand3P) but the older class name was hanging around in the Jenkins workspace, and being bundled into the Docker image.
We deleted the workspace, re-ran the build, and all was fine.
I'm getting the following error since I added neo4j to my spring mvc project (add default packages like spring-context, spring-webmvc, etc).
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: AnnotationConfigUtils.processCommonDefinitionAnnotations(…) is not public! Make sure you're using Spring 3.2.5 or better. The class was loaded from file:/Users/mariamdost/Downloads/sts-bundle/pivotal-tc-server-developer-3.1.1.RELEASE/base-instance/wtpwebapps/CodeChallenge/WEB-INF/lib/spring-context-3.1.1.RELEASE.jar.
Offending resource: ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]; nested exception is java.lang.IllegalStateException: AnnotationConfigUtils.processCommonDefinitionAnnotations(…) is not public! Make sure you're using Spring 3.2.5 or better. The class was loaded from file:/Users/mariamdost/Downloads/sts-bundle/pivotal-tc-server-developer-3.1.1.RELEASE/base-instance/wtpwebapps/CodeChallenge/WEB-INF/lib/spring-context-3.1.1.RELEASE.jar.
org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
As the error says I then deleted the default spring-context (3.1.1) and added again and it got rid of that error but then I ran into even more errors. The next error was that spring-expression and spring-context were of different versions so I fixed it by adding spring-expression and excluding spring-expression from neo4j. Then I ran into the final error:
Java.Lang.NoSuchMethod: tried to access method org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingletonMutex()
The last error I cannot find any solution. So reverted back to my initial state and I'm wondering is there another db I can use that will work with my current project setup? If not then how can I fix the current error I have? Any help would be greatly appreciated. Thanks in advance.
Seems like you have added some incompatible spring jars. The java.lang.NoSuchMethod error suggests that the expected method is not found in the dependent class . You would need to have look at the classes that you have added and correct them.
I am developing a webapp in cloudbees platform and trying to add functionality for sending mail.
I am following https://wiki.cloudbees.com/bin/view/RUN/SendGrid documentation and as per the document we can get the mail session using below:
Context initCtx = new InitialContext();
Session session = (Session) initCtx.lookup("java:comp/env/mail/SendGrid");
But when running thie code in cloud i am getting:
java.lang.ClassCastException: javax.mail.Session cannot be cast to javax.mail.Session.
the problem seems to be with javax.mail.jar
i have downloaded the latest jar from https://java.net/projects/javamail/pages/Home .
As i understand the version which is required in cloud bees is different from what i am deploying.Can anyone help in getting correct jar for this particular purpose.
Note: I have added send grid to my stack in cloudBees.
I think you have more than one version of the javax.mail.
Indeed, the java mail session jars should be already provided by the container.
You can refer to this, as example: https://github.com/CloudBees-community/tomcat7-sendgrid-clickstart/blob/master/pom.xml
Try to remove your mail jar and if it still does not work and you are using maven try using the dependency plugin with
mvn dependency:tree -Dverbose
to check if you have conflicts with mails dependencies.
Duplicate Problem Resolved with Spring Framework on Cloudbees
I had the same problem only from Spring and can confirm it was from including javax-mail in the Maven dependencies (which also brings in the mail jar). After taking out the dependency/jar file I was having a problem with the constructor for org.springframework.mail.javamail.JavaMailSenderImpl not liking the type of the argument from jndi, however. At least the original error seemed to be objecting to the same class rather than saying it didn't know the type/name/etc. Finally, taking out passing the session to the constructor and putting it in the property (which in theory should do the same thing, I believe) fixed the problem:
<jee:jndi-lookup id="mailSource"
jndi-name="java:comp/env/mail/SendGrid"
expected-type="javax.mail.Session" />
<bean id="mailSender"
class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="session" ref="mailSource" />
</bean>
I'm trying to deploy an app on tomcat 7 that uses spring 3.1.1 and weblogic 10.3, but I keep getting a NoClassDef exception:
java.lang.NoClassDefFoundError: Could not initialize class weblogic.jndi.Environment at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506) ~[spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
I've double checked and and the weblogic jar is present on WEB-INF/lib and it does contain said class:
jar tf WEB-INF/lib/weblogic.jar | grep /Environment.class
weblogic/cluster/messaging/internal/Environment.class
weblogic/jndi/Environment.class
org/mozilla/javascript/tools/shell/Environment.class
this happens when a spring bean factory tries to build this bean on my root-context.xml
<beans:bean
id="jmsConnectionFactory"
class="org.springframework.jndi.JndiObjectFactoryBean"
p:jndiTemplate-ref="jndiTemplate"
p:jndiName="weblogic.jms.ConnectionFactory" />
I thought it might be some classpath issue, but I have been playing around with the MANIFEST.MF of the webapp and this problematic jars(spring & weblogic) for a while now, without any luck.
Any ideas on what can be causing this?
I believe using weblogic.jar directly in the classpath does not work. You need to create wlfullclient.jar and put it in WEB-INF/lib.
Follow the instructions given here: http://middlewaremagic.com/weblogic/?p=558
I created a cxf/spring project with:
mvn archetype:create -DarchetypeGroupId=org.apache.cxf.archetype -DarchetypeArtifactId=cxf-jaxws-javafirst
The resulting project has a HelloWorld.java interface annotated as a #WebService, and a HelloWorldImpl.java annotated with an endpointInterface=mypackage.HelloWorld.
There's a beans.xml file containing:
<jaxws:endpoint
id="helloWorld"
implementor="mypackage.HelloWorldImpl"
address="/HelloWorld" />
If I want to add more services, it looks like I'm expected to keep adding new endpoints in beans.xml. Since the classes are already annotated as #WebService, why can't it auto-discover any new services within some package / search path? Is there some way I can configure this project to do that?
Basically, I'm just trying to avoid repeating myself. The information is already going to be in the annotations so I don't want to have to edit additional files each time I add a service.
If I remove the jaxws:endpoint tag in beans.xml, and then mvn install tomcat:run, localhost:8080/myArtifactId just shows me a page saying there are not services defined.
When you use the CXF you should know that all the endpoints you added are managed by the CXFServlet that uses Spring context to find them out. beans.xml is a Spring context's config file. So if you remove the <jaxws:endpoint/> node from that file your Spring context and hence the CXFServlet will have no way to find your service endpoints.