Spring-Webflow JSF intgration war example(http://www.springsource.org/webflow-samples/spring-booking-faces.war) file from spring site is not working in GlassfishV3 server. It works in Tomcat6.0.
In Glassfish, It throws following exception
Caused by: java.lang.UnsupportedOperationException
at javax.faces.context.FacesContext.getAttributes(FacesContext.java:141)
at com.sun.faces.util.RequestStateManager.get(RequestStateManager.java:194)
at com.sun.faces.util.Util.getFacesMapping(Util.java:564)
at com.sun.faces.application.view.MultiViewHandler.derivePhysicalViewId(MultiViewHandler.java:483)
at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:142)
at org.springframework.faces.webflow.FlowViewHandler.restoreView(FlowViewHandler.java:77)
at org.springframework.faces.webflow.JsfViewFactory.getView(JsfViewFactory.java:97)
at org.springframework.webflow.engine.ViewState.resume(ViewState.java:198)
at org.springframework.webflow.engine.Flow.resume(Flow.java:551)
at org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:263)
... 40 more
I received a similar error that you are facing sometime back . Try replacing your JSF jars with the following jars.I guess it is using Primefaces too . Use following combination of jars
[INFO] +- com.sun.faces:jsf-api:jar:2.0.3-b05:compile
[INFO] +- com.sun.faces:jsf-impl:jar:2.0.3-b05:runtime
[INFO] +- org.primefaces:primefaces:jar:2.2.RC2:compile
Please let me know if you still face any problem
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed last year.
The community reviewed whether to reopen this question last year and left it closed:
Original close reason(s) were not resolved
Improve this question
I'm a beginner with spring boot. I'm involved in the beginning of a project where we would build rest services using spring boot. Could you please advise the recommended directory structure to follow when building a project that will just expose rest services?
From the docs:, this is the recommended way
The following listing shows a typical layout:
com
+- example
+- myapplication
+- Application.java
+- customer
+- Customer.java
+- CustomerController.java
+- CustomerService.java
+- CustomerRepository.java
+- order
+- order.java
+- OrderController.java
+- OrderService.java
+- OrderRepository. java
The Application. java file would declare the main method, along with the basic SpringBootApplication as follows:
package com.example.myapplication;
import org. springframework.boot.springApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication public class Application {
public static void main(string[] args)
{
springApplication.run(Application. class, args);
}
}
config - class which will read from property files
cache - caching mechanism class files
constants - constant defined class
controller - controller class
exception - exception class
model - pojos classes will be present
security - security classes
service - Impl classes
util - utility classes
validation - validators classes
bootloader - main class
You do not need to do anything special to start. Start with a normal java project, either maven or gradle or IDE project layout with starter dependency.
You need just one main class, as per guide here and rest...
There is no constrained package structure. Actual structure will be driven by your requirement/whim and the directory structure is laid by build-tool / IDE
You can follow same structure that you might be following for a Spring MVC application.
You can follow either way
A project is divided into layers:
for example: DDD style
Service layer : service package contains service classes
DAO/REPO layer : dao package containing dao classes
Entity layers
or
any layer structure suitable to your problem for which you are writing problem.
A project divided into modules or functionalities or features and A module is divided into layers like above
I prefer the second, because it follows Business context. Think in terms of concepts.
What you do is dependent upon how you see the project. It is your code organization skills.
Though this question has an accepted answer, still I would like to share my project structure for RESTful services.
src/main/java
+- com
+- example
+- Application.java
+- ApplicationConstants.java
+- configuration
| +- ApplicationConfiguration.java
+- controller
| +- ApplicationController.java
+- dao
| +- impl
| | +- ApplicationDaoImpl.java
| +- ApplicationDao.java
+- dto
| +- ApplicationDto.java
+- service
| +- impl
| | +- ApplicationServiceImpl.java
| +- ApplicationService.java
+- util
| +- ApplicationUtils.java
+- validation
| +- impl
| | +- ApplicationValidationImpl.java
| +- ApplicationValidation.java
DAO = Data Access Object.
DTO = Data Transfer Object.
Use Link-1 to generate a project. this a basic project for learning. you can understand the folder structure.
Use Link-2 for creating a basic Spring boot project.
1: http://start.spring.io/
2: https://projects.spring.io/spring-boot/
Create a gradle/maven project Automatically src/main/java and src/main/test will be created. create controller/service/Repository package and start writing the code.
-src/main/java(source folder)
---com.package.service(package)
---ServiceClass(Class)
---com.package.controller(package)
---ControllerClass(Class)
Please use Spring Tool Suite (Eclipse-based development environment that is customized for developing Spring applications). Create a Spring Starter Project, it will create the directory structure for you with the spring boot maven dependencies.
I am configuring spring mvc project to use angular 2 without spring boot.
my directory structure is :
Project
|
+--src
|
+--resources
| |
| +--css
| |
| +--js
| |
| +--angular
| |
| +--app/
| |
| +--node_modules/
| |
| +--package.json,systemjs.config.js,tsconfig.json
|
|
+--WEB-INF
|
+--pages
|
+--index.jsp
I have included the follwing lines in index.jsp
<!-- 1. Load libraries for angular 2 setup -->
<!-- Polyfill(s) for older browsers -->
<script src="${pageContext.request.contextPath}/resources/angular/node_modules/core-js/client/shim.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/angular/node_modules/zone.js/dist/zone.js"></script>
<script src="${pageContext.request.contextPath}/resources/angular/node_modules/reflect-metadata/Reflect.js"></script>
<script src="${pageContext.request.contextPath}/resources/angular/node_modules/systemjs/dist/system.src.js"></script>
<!-- 2. Configure SystemJS -->
<script src="${pageContext.request.contextPath}/resources/angular/systemjs.config.js"></script>
<script>
System.import('${pageContext.request.contextPath}/resources/angular/app').catch(function(err){ console.error(err); });
</script>
I have followed the angular 2 quick start
https://angular.io/guide/quickstart
All the files contain the same code mentioned in the above link. The only thing i have changed is:
Copied app directory, node_modules directory and configuration files to resources directory and modified index.jsp to load it from there.
It is throwing the following exception:
GET http://localhost:8085/Phoenix/resources/angular/app/ 404 (Not Found) in browser console. Please suggest anything to fix this issue.
Follow below steps to achieve our main goal, to run SPRINGMVC + Angular2 on a single server.
Create normal Dynamic web project.
Add all dependancy required for spring or user maven pom.xml
Open CMD, navigate to angular2 application. Hit command npm install and then ng build or use ng build --prod for production.This command will create a "dist" folder, copy all files including all folders.
Paste those files and folders into WebContent directory.
Last thing, you need to change basehref="./" in index.html. Now you are ready to run server or you can deploy war file and serve it with tomcat or other servers.
Checkout this thread, I have mentioned file structure and its working fine.
I know there are many drawbacks to use these way for running application on a single server, but if it must required you can follow this.
If you change anything at angular side, you need to copy paste dist folder all time and then you can deploy it!
I think you are missing the Ressourcehandler configuration and also the Controller on Java site - Here are some examples for using Spring MVC and Angular
I've just started working with maven so if this is an idiotic or obvious question please bear with me.
I've got a soap server that I built for one of our servers, it requires things such as boneCP, slf4j, connector-java, so I added these to the POM.xml and when I just run or debug the soap server it works fine. However whenever I try to build it I get:
Exception in thread "main" java.lang.NoClassDefFoundError: com/ning/http/client/AsyncHttpProvider
at org.sonatype.aether.connector.async.AsyncRepositoryConnectorFactory.newInstance(AsyncRepositoryConnectorFactory.java:106)
at org.sonatype.aether.impl.internal.DefaultRemoteRepositoryManager.getRepositoryConnector(DefaultRemoteRepositoryManager.java:346)
at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:453)
at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:216)
at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:193)
at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:281)
at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(DefaultArtifactDescriptorReader.java:186)
at org.sonatype.aether.impl.internal.DefaultRepositorySystem.readArtifactDescriptor(DefaultRepositorySystem.java:279)
at org.apache.maven.plugin.internal.DefaultPluginDependenciesResolver.resolve(DefaultPluginDependenciesResolver.java:115)
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getPluginDescriptor(DefaultMavenPluginManager.java:142)
at org.apache.maven.plugin.DefaultBuildPluginManager.loadPlugin(DefaultBuildPluginManager.java:59)
at org.apache.maven.plugin.prefix.internal.DefaultPluginPrefixResolver.resolveFromProject(DefaultPluginPrefixResolver.java:139)
at org.apache.maven.plugin.prefix.internal.DefaultPluginPrefixResolver.resolveFromProject(DefaultPluginPrefixResolver.java:122)
at org.apache.maven.plugin.prefix.internal.DefaultPluginPrefixResolver.resolve(DefaultPluginPrefixResolver.java:86)
at org.apache.maven.lifecycle.internal.MojoDescriptorCreator.findPluginForPrefix(MojoDescriptorCreator.java:262)
at org.apache.maven.lifecycle.internal.MojoDescriptorCreator.getMojoDescriptor(MojoDescriptorCreator.java:222)
at org.apache.maven.lifecycle.internal.DefaultLifecycleTaskSegmentCalculator.calculateTaskSegments(DefaultLifecycleTaskSegmentCalculator.java:106)
at org.apache.maven.lifecycle.internal.DefaultLifecycleTaskSegmentCalculator.calculateTaskSegments(DefaultLifecycleTaskSegmentCalculator.java:86)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:98)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: java.lang.ClassNotFoundException: com.ning.http.client.AsyncHttpProvider
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
... 32 more
I've searched on google but cant seem to find anything relating to this issue when using maven, only when declaring the classpath manually.
Am I missing something?
sorry if this is an obvious or stupid question, as I said I'm just starting out with maven.
EDIT:
Thanks for the help!
I ran the command to check dependencies and got
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # auth ---
[INFO] com.v2.auth:auth:jar:0.0.1-SNAPSHOT
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] +- ch.qos.logback:logback-classic:jar:1.0.13:compile
[INFO] | +- ch.qos.logback:logback-core:jar:1.0.13:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.5:compile
[INFO] +- com.jolbox:bonecp:jar:0.8.0.RELEASE:compile
[INFO] | +- com.google.guava:guava:jar:15.0:compile
[INFO] | \- (org.slf4j:slf4j-api:jar:1.7.2:compile - omitted for conflict with 1.7.5)
[INFO] \- mysql:mysql-connector-java:jar:5.1.6:compi
so it seems like the problem is coming from guava and logback not playing nice? so it looks like I need to find a way to exclude that slf4j version from being included in Guava?
A common problem with Maven is that sometimes you have dependencies conflicts, especially when you inherit dependencies from a parent POM.
The parent POM might define a version of the library, and your POM define a newer one. From here, there are two possibilities:
-The class not found is included in the older version, but not in the new one, and the new is the one that is being used. In fact, this could happen without the need of conflicting dependencies to exist: you can just have included the newest version instead of the old one.
-The class not found is included in the newer version, but the dependency management causes the old version to be the one used.
Check your dependencies map, and you will find if there is any conflict between versions.
I have a simple Jersey jax rs hello world application that I am trying to deploy to my tomcat server so i can call the resource url and check and see if it gives me the required output but when i set the context path in the web.xml it doesnt deploy to the server it does however when i take the servlet information out and just leave a blank web.xml meaning this must be my problem. Here is the contents of my web.xml.
`<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Web App</display-name>
<servlet-name>ServletContainer</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletContainer</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
</web-app>
As requested here is the stacktrace of the error
[INFO] [war:war {execution: default-war}]
[INFO] Packaging webapp
[INFO] Assembling webapp[app1] in [C:\Users\leo\4thYearUni\Project\app1\target\app1]
[INFO] Processing war project
[INFO] Copying webapp resources[C:\Users\leo\4thYearUni\Project\app1\src\main\webapp]
[INFO] Webapp assembled in[170 msecs]
[INFO] Building war: C:\Users\leo\4thYearUni\Project\app1\target\app1.war
[INFO] [tomcat:redeploy {execution: default-cli}]
[INFO] Deploying war to http://localhost:8080/app1
[INFO] OK - Undeployed application at context path /app1
[INFO] FAIL - Failed to deploy application at context path /app1
If anyone has any ideas or workarounds this would be much appreciated
Thank you
Chris
First of all, if something is failing deployment, the first hint at a solution is to look at the logs of the application server to answer the question "Why is this failing?"
Things don't just "fail", they will give error messages and exceptions and stacktraces and information about what is actually occurring. Attempting to guess why something fails with none of this knowledge amounts to just guesswork.
As a guess, make sure that the class com.sun.jersey.spi.container.servlet.ServletContainer is on the classpath of the web application (i.e. in the WEB-INF/lib directory).
Kind of drive-by answering here, but I note a hanging end tag in the middle of your web.xml:
</servlet>
this would stop it parsing....
Turns out there was some confusion about the web.xml files i was editing , and when found the correct web.xml and sorted the hanging servlet tag this sorted the problem . Thank you everyone for all your help and patience as I am completely new to maven.
One of the possible reasons for this is this sort of entry in ant
<zipfileset dir="./mywebcontent/" prefix="/" />
remove prefix="/", it spoils your archive
In my case, it was because when working on https://netbeans.org/kb/docs/web/ajax-quickstart.html tutorial, I didn't tick "add information to the deployment descriptor (web.xml)" during the create new servlet wizard.
Although I deleted that servlet and created the servlet again, this time ticking the checkbox, I think this is what caused my 'context.xml' to contain <Context antiJARLocking="true" path="/MyAjaxApp"/> which caused the error.
So when I changed the line to <Context antiJARLocking="true" path="/AutoCompleteServlet"/>, everything worked fine.
I am using NetBeans 6.8 for building Spring MVC application.
Technologies :
Spring MVC 2.5
Derby DB
Hibernate for ORM
GlassFish v3 server
I use New JPA Controller Classes from Entity Classes for adding ORM file. It is supposed to generate class for managing queries with my POJO files.
Problem is, that NetBeans generates following code, and won't compile :
public int getBrandCount() {
EntityManager em = getEntityManager();
try {
CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
Root<Brand> rt = cq.from(Brand.class);
cq.select(em.getCriteriaBuilder().count(rt));
Query q = em.createQuery(cq);
return ((Long) q.getSingleResult()).intValue();
} finally {
em.close();
}
}
At the picture, there is NetBeans error :
It looks like method getCriteriaBuilder of Entity Manager Interface is unimplemented. Or some other reason why I can't use it in code.
I don't know what other info should I provide, so please ask if anything comes to your mind.
Thanks
I ran into this problem and found that I had the Hibernate JPA library (included with Netbeans) above Persistence (JPA 2.0) library in the project library manager list. I moved Persistence above Hibernate and it cleared up the compile issues.
NetBeans is generating JPA 2.0 code so you need the JPA 2.0 API on your class path to compile your code (and a JPA 2.0 provider to run it). Since you're using Hibernate, here are the required libraries to use Hibernate Entity Manager 3.5.1-Final:
org.hibernate:hibernate-entitymanager:jar:3.5.1-Final:compile
+- org.hibernate:hibernate-core:jar:3.5.1-Final:compile
| +- antlr:antlr:jar:2.7.6:compile
| +- commons-collections:commons-collections:jar:3.2:compile
| +- dom4j:dom4j:jar:1.6.1:compile
| | \- xml-apis:xml-apis:jar:1.0.b2:compile
| \- javax.transaction:jta:jar:1.1:compile
+- org.hibernate:hibernate-annotations:jar:3.5.1-Final:compile
| \- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile
+- cglib:cglib:jar:2.2:compile
| \- asm:asm:jar:3.1:compile
+- javassist:javassist:jar:3.9.0.GA:compile
\- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:compile
I have the similar problem when deploying project with
Netbeans 7.0.1
Apache Tomcat 7
Hibernate 3
When mapping the class entity from database, i mixed it with annotation so the controller can be easily generated by Java Persistence Controller. The problem is same. The getCriteriaBuilder is the problem since it isn't supported by JPA 1.0. I have checked it in the project classpath and i found that Persistence Library is miss used since the project import two persistence library which is persistence library from ejb3 and EclipseLink(JPA2.0).
When i remove the ejb persistence library, the getCriteriaBuilder works fine for me.