I am trying to deploy an application build from https://github.com/spring-guides/gs-convert-jar-to-war to local glassfish4. And it delpoys well for the first time (if I can call some exceptions from the framework good behaviour). At least, I can open the project's index page in browser.
But if I try to undeploy it and re-deploy, or just overwrite .war file in autodeploy directory, deployment fails. And nothing seems to be added to glassfish log file.
The projects I published from eclipse using some its mechanisms deployed and re-deployed successfully.
Here is the log with related contents:
http://pastebin.com/zSeMw5tC
What can be the problem?
I did some experiments with Glassfish a while ago. The CDI implementation is really broken IMO (it shouldn't load classes to scan them for annotations), but the apps I tried worked on GF 4 if there is a WEB-INF/classes/META-INF/beans.xml containing
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd"
bean-discovery-mode="none">
<scan>
<exclude name="org.springframework.**" />
<exclude name="org.apache.**" />
<exclude name="com.google.**" />
</scan>
</beans>
Nothing I did ever worked in GF 3 (older CDI spec and no way to exclude things I think).
Related
What do I want:
I want to set up an automated deployment pipeline - my plan is as follows:
I create two .war files, let's call them prod.war and test.war, using a gradle build script, and deploy them to my tomcat server.
My problem:
The prod.war needs to access the production database (mongoprod), and the test.war to the test database (mongotest).
My attempt:
I thought I could use Spring profiles and simply...
...change a line in my application-context.xml from:
<mongo:db-factory id="mongoDbFactory" dbname="mongoprod"/>
to:
<mongo:db-factory id="mongoDbFactory" dbname="${mongo.db.name}"/>
...create two files, in the same folder (<filename>:<content>):
application-production.properties:mongo.db.name=mongotest
application-test.properties:mongo.db.name=mongoprod
...execute some gradle build script with an argument that can change the profile to production or test and then use the corresponding .property file to insert the desired mongo dbname...but that's where I ran out of luck!
I tried to add this to my build.gradle file:
bootRun { args = ["--spring.profiles.active=" + profiles] }
and then run it with $ ./gradlew bootRun -Ptest
but I just get the error:
Main class name has not been configured and it could not be resolved
and besides that I haven't used bootRun before, only a war task so far to create my .war files:
war {
archiveName = 'application.war'
dependsOn 'lessc', 'webpack'
from "$buildDir/webapp"
exclude 'WEB-INF/js/main.js'
rename 'main\\.min\\.js', 'main.js'
}
Does anyone know how I can get my problem to work or could give me useful information on this?
You need to provide a main class name to be run by the bootRun task, for example as follows:
springBoot {
mainClassName = 'org.baeldung.DemoApplication'
}
You can read more about it in thos tutorial
Update:
configuration for application plugin could be done as follows
application {
mainClassName = 'org.gradle.sample.Main'
}
As it's said in the plugin docs
I found out that for my case it turned out to be much easier (and I think better) to decide during runtime wether a test or a production DB should be used and I solved it the following way:
In my application-context.xml I created two beans instead of one, one for each DB (I had to nest them below a "root"-beans, otherwise I got errors during building):
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.5.xsd">
<beans profile="prod">
<mongo:db-factory id="mongoDbFactory" dbname="mongoprod"/>
<mongo:mapping-converter id="mongoConverter" base-package="my.company.project">
<mongo:custom-converters base-package="my.company.project"/>
</mongo:mapping-converter>
<mongo:gridFsTemplate bucket="images" converter-ref="mongoConverter" db-factory-ref="mongoDbFactory"/>
</beans>
<beans profile="test">
<mongo:db-factory id="mongoDbFactory" dbname="mongotest"/>
<mongo:mapping-converter id="mongoConverter" base-package="my.company.project">
<mongo:custom-converters base-package="my.company.project"/>
</mongo:mapping-converter>
<mongo:gridFsTemplate bucket="images" converter-ref="mongoConverter" db-factory-ref="mongoDbFactory"/>
</beans>
</beans>
In order for the .war file creation to work properly I had to set enabled to true in my build.gradle file here:
war {
enabled = true //without this no .war file was created before - https://stackoverflow.com/a/52315049/4120196
dependsOn 'lessc', 'webpack'
from "$buildDir/webapp"
exclude 'WEB-INF/js/main.js'
rename 'main\\.min\\.js', 'main.js'
}
I then created a .war file, copied it and renamed it - so I had two: prod.war and test.war and put them into my Tomcat 8.5_Tomcat8.5.23\webapps folder (I'm working on Win10 in case this differs on other systems). Then I created two .xml files with the same name as the .war files where I defined the spring profile that decides which bean to take in Tomcat 8.5_Tomcat8.5.23\conf\Catalina\localhost:
prod.xml
<Context>
<Environment name="spring.profiles.active" value="prod" type="java.lang.String" override="false" />
</Context>
test.xml
<Context>
<Environment name="spring.profiles.active" value="test" type="java.lang.String" override="false" />
</Context>
I started up tomcat and finally everything worked as I wanted it to.
If you have any hints how my solution can be improved feel free to comment :)
I feel like my application-context.xml could be shortened somehow for example...
I need some help: I have one EAR-File, containing one WAR-File, one EJB-Jar-File and some "shared" libs:
aopalliance-1.0.jar commons-logging-1.1.1.jar log4j-1.2.16.jar spring-aop-4.0.5.RELEASE.jar spring-beans-4.0.5.RELEASE.jar spring-context-4.0.5.RELEASE.jar spring-context-support-4.0.5.RELEASE.jar spring-core-4.0.5.RELEASE.jar spring-expression-4.0.5.RELEASE.jar
The War File has a Context initializer which find the spring config and loads everything well.
I now want to use another Spring Context for the EJB Jar.
My EJB is defined as
#Stateless(mappedName = "ejb/SpringRocks")
#RemoteHome(com.ibm.websphere.ola.ExecuteHome.class)
#Interceptors(SpringBeanAutowiringInterceptor.class)
public class WolaUseCaseOne {
#Autowired
private DummyService dummyService;
/* ...More stuff here */
Inside the EJB-JAR, there is also a beanRefContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="myEjb" name="myEjb" class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg value="classpath*:META-INF/spring/simpleEjb.xml" />
</bean>
</beans>
The simpleEjb.xml is is also inside the EJB-Jar and is defining a very simple Bean:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="myDummyService" class="com.provinzial.beispielanwendung.batch.wola.DummyServiceImpl" />
</beans>
As described, the WEB Part works perfect, but when the EJB is called, the SpringBeanAutowiringInterceptor is called, but seems to do nothing. What do I have to do, to get a Spring Context created?! My hope was that it is initialized when the EJB is created. I created a Subclass of SpringBeanAutowiringInterceptor with some loggers, but the class is only created, no method is called !
What else do I have to do? Or does anybody have a valid EAR File example?
I think the Problem is that inside the EJB Module no context is initialized...
Greets
Timo
I was facing similar issue with my EJB (no WAR). This is what fixed mine,
I was missing the spring-aop jar on my classpath. I see you have it so good there.
In my ejb-jar.xml file, I set the meta-data flag to true so I did not get prompted on deployment to complete.
I set to "false" for one deployment to see what IBM generated for me. In the ejb-jar.xml it added the following (my MDB is named TaskMDB),
<assembly-descriptor>
<interceptor-binding>
<ejb-name>TaskMDB</ejb-name>
<interceptor-class>org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor</interceptor-class>
</interceptor-binding>
</assembly-descriptor>
<interceptors>
<interceptor>
<interceptor-class>org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor</interceptor-class>
<post-activate>
<lifecycle-callback-class>org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor</lifecycle-callback-class>
<lifecycle-callback-method>autowireBean</lifecycle-callback-method>
</post-activate>
<pre-passivate>
<lifecycle-callback-class>org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor</lifecycle-callback-class>
<lifecycle-callback-method>releaseBean</lifecycle-callback-method>
</pre-passivate>
<post-construct>
<lifecycle-callback-class>org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor</lifecycle-callback-class>
<lifecycle-callback-method>autowireBean</lifecycle-callback-method>
</post-construct>
<pre-destroy>
<lifecycle-callback-class>org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor</lifecycle-callback-class>
<lifecycle-callback-method>releaseBean</lifecycle-callback-method>
</pre-destroy>
</interceptor>
</interceptors>
Then I added what IBM generated (the assembly-descriptor and interceptors stanzas) back to my ejb-jar.xml and set the metadata-complete back to true.
Then it worked. Hope this helps.
Here is the full ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="3.1" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd">
<display-name>ares-api-uow-ejb</display-name>
<enterprise-beans>
<message-driven id="TaskMDB">
<ejb-name>TaskMDB</ejb-name>
<ejb-class>something.api.uow.ejb.mdb.TaskMDB</ejb-class>
<messaging-type>javax.jms.MessageListener</messaging-type>
<transaction-type>Bean</transaction-type>
</message-driven>
</enterprise-beans>
</ejb-jar>
This is an integration issue of Drools KIE and Spring MVC Web V 3.2.3 where google just isn't finding any references to so I'll try my luck here ...
I'm integrating Drools KIE and Spring 3.2.3.RELEASE (MVC Web)- and I'm getting the following error:
No setter found for property 'kBaseName' in class 'org.kie.spring.factorybeans.KBaseFactoryBean'
[config set: maven-spring-drools/web-context application-config.xml
/maven-spring-drools/src/main/resources/spring
The Project is a pure Maven project w/out any outside natures imposed upon it (aka. Drools/Spring).
It's complaining that it can't find the setters for the kBaseName', which is set here:
I'm using a kmodule.xml found in the META-INF dir under the src/main/resources dir.
Can anyone help me discover the disconnect?
Moreover - do I have to do it this way? The project executes the SPring MVC Web App just fine and the Drools KIE test case runs perfectly in the same Maven project. Can't I just integrate them programmatically instead?
Many thanks in advance ... :-)
The offending file: application.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:kie="http://drools.org/schema/kie-spring"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="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://drools.org/schema/kie-spring http://drools.org/schema/kie-spring.xsd">
<context:component-scan base-package="com.versaggi.springweb"/>
<kie:kmodule id="ksession-rules">
<kie:kbase name="rules" packages="rules">
</kie:kbase>
</kie:kmodule>
<bean id="kiePostProcessor" class="org.kie.spring.KModuleBeanFactoryPostProcessor" />
</beans>
I am using jRebel version 5.0.0 in my Spring project. Everything works well, any changes in Java, JSP or JS files was affected immediately. But when I modify some message keys in MessageResource.properties file, it does not reload the new modification. All of my resource bundle files are in same directory: myproject\src\main\webapp\WEB-INF**;
and in target folder (built files) **myproject\target\myproject\WEB-INF.
I do not use external jRebel config file, but jRebel plugin for Eclipse, so I found the auto-generated jRebel config file in myproject\target\myproject\WEB-INF\classes\jrebel.xml.
Here is its content:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://www.zeroturnaround.com/alderaan/rebel-2_0.xsd">
<classpath>
<dir name="D:/workspace/.projects/myproject/target/myproject/WEB-INF/classes">
</dir>
</classpath>
<web>
<link target="/">
<dir name="D:/workspace/.projects/myproject/src/main/webapp">
</dir>
</link>
</web>
</application>
Could you please help me this issue? Thank you so much.
I have a web-application on RAD 7.5. I am building the application using Maven and deploying on WebSphere 6.1.
A part of my web.xml is:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:services.xml</param-value>
</context-param>
This is the only place where I am referencing services.xml.
My services.xml is in folder
FruitApplication/src/main/resources/services.xml
After building with maven, services.xml is in the following path in the target folder
target/FruitApplication-1.0.0/WEB-INF/classes/services.xml
On deployment, I continuously get below mentioned error. However, on building the application two three times, it disappears on its own and then reappears again haphazardly.
What is the actual cause of this error ?
How to solve this error ?
The top of my services.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
Is something needs to be changed here ???
Below is the complete pom.xml I am using for "maven-install":
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>FruitApplication</groupId>
<artifactId>FruitApplication</artifactId>
<packaging>war</packaging>
<version>1.0.0</version>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.1</version>
<configuration>
<archive>
<manifestFile>
src/main/webapp/META-INF/MANIFEST.MF
</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
... dependencies here ...
</dependencies>
</project>
I have already tried all the below three options:
<param-value>classpath:services.xml</param-value>
<param-value>classpath:/services.xml</param-value>
<param-value>WEB-INF/classes/services.xml</param-value>
How I am deploying:
I am removing the application from the server by right clicking on server and "add or remove applications"
I am doing a run-as "maven-clean" and then run-as "maven-install" on the application and again adding the application by right clicking on the server and "add or remove applications"
Did you try classpath:/services.xml? The leading slash means to pull the resource from the root of the classpath. Without it, the file is expected to be in the package of whatever class is loading it (which I admit I don't know what that would be in this case).
See http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Class.html#getResourceAsStream%28java.lang.String%29
Select project where the reource files exist.Right click - Build path - configure build path - sources -Add folder - add the folder where you resource file exist.This would add the folder to you class path.
If the above project/jar is part of another WAR/EAR then select that WAR and/or EAR - properties - j2ee module dependecies and select the above project to get added to build path.
Restart the server.
Figure out if its Websphere/RAD or a application issue?
First build the war file and drop it in a Tomcat container and check if you still see the error.
1. If you see then copy the services.xml to WEB-INF and WEB-INF/classes directory and see if it works.
2. Also check your CLASSPATH system environment variable, system CLASSPATH can override your application classpath.
If everything is fine with Tomcat, there is something specific to Websphere/RAD:
3. Check you websphere environment, I recall there is some option in websphere where you can set/override/prefix the classpath.