jars required for REST service using spring - java

I am trying to implement a REST services using spring. I have added below JARS in the WEB-INF/lib and in Build path as well.
Spring core
Spring web
Spring MVC
Spring Context
Spring aop
Spring aspects
Common loggin
JSTL.
I have integrated the server in my Eclipse and started. When i try to hit the URL given in Spring controller, I am getting Resource not found Error. Exception I ma getting is ClassNotFound.
In the same project i have a HTML page when i try to hit it, its working fine.
Any jar i have to import or what may be the possible reason?

Have you explored SpringBoot? It is much easier to implement a REST based service. There are just 3 or 4 dependencies. You can find an example to implement a REST service here http://projects.spring.io/spring-boot/#quick-start

Search for the class using some utility like http://findjar.com and make sure that required dependency has been included in your project.
Do mvn dependency:tree to make sure that the respective project has been included.
If the respective project has been included, make sure that the class is there in the included version of the project.

Related

How to configure a Spring Boot Application that uses tomcat and has a dependency to another Application uses tomcat

I have a Spring Boot application (App1) that uses an embedded Tomcat. To specify the Port I added server.port=8080 to the application.properties in my main application
and it works fine.
Now I add a dependency to another Spring Boot application (App2) in the pom.xml (because in App1 I need access to the Beans from App2). App2 uses also an embedded Tomcat on a different port.
But when I run App1 it crashes because App2 want to also use the same server.port and configurations - that obviously cannot work.
Is this even possible what I want to achieve? And how would I do this that I can run both App2 in App1? If this is not possible, is it possible to access the Beans from App2 in App1?
I see two options, depending on which one suits your use case conceptually:
you have two Spring Boot applications that need to share the same code: extract this code to a separate project (a regular Java library), build it as a jar file and include into both projects as a dependency; an example could be found in the Creating a Multi Module Project guide;
you have two Spring Boot applications, one of them needs to access the functionality of another: provide and access this functionality as an API, instead of directly importing the beans. There are multiple ways to do this. For example, you could expose the bean functionality as a REST API using Spring's #RestController, and access them from the other side using RestTemplate. See the following guides: Building a RESTful Web Service, Consuming a RESTful Web Service

Importing spring boot jar into another app without #ComponentScan and Xml Configurations

I'm looking for a generic/clean solution to import a spring boot jar application into another spring boot application without doing #ComponentScan(package name of the application), without the xml configuration.
If I didn't say #Componentscan in the base application, #Autowired is not working, which is quite understandable.
So in general writing libraries with spring boot is not a ideal way?
Finally, I went with #Import(ApplicationConfiguration)which I find it quite neat.
I had a multi-level project structure so on each of the sub-module created a configuration file which initiate the required beans and then in the parent module, I have used #Import.

Spring from a GWT

I have the next problem. I did simple project using Spring and Hibernate. Here is the structure of my project: (oh, I cant attach images).
Structure:
module "service" - the whole business logic;
module "war" - generates war file with client side part.
In a module war I have an .jsp page that generates table with data from database. There are also a few servlets. In my .jsp page I used Spring to get my service with movies.
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
MovieService bean = (MovieService) context.getBean("movieService");
List<Movie> movieList = bean.getAllMovies();
Now, I need to use GWT here. How can I use Spring in GWT app? I just add new module with GWT framework, and in entry class I can not use WebAppContext...
What should I use? However, I can directly use my service class, but it is not cool :) I want to use it like in .jsp page.
Thanks for any help!
If I understand correctly you have 3 options:
Use spring4gwt (maybe project is dead)
Use your controller as RESTful service (possibly it's not what you want)
Use spring like in this example
Also here you can find example of self-made analogue of spring4gwt, maye it works too

Using Jersey and Spring in a Project

I want to create a REST web service using Jersey. I also want to use Spring in the project. Now, my questions is the following:
I don't see any reason for integrating these 2 together in my application. So, I should be able to use Spring for bean management and Jersey for creating the web service. Am I correct, or Spring and Jersey somehow have to be integrated.
I see that there is a jersey-spring maven project, and so, I assume that this is for the purpose of integrating jersey and spring together. My question here is do I get any benefit of using this integrated form rather than simply use Jersey and Spring separately each for its own functionality?
Thanks,
Cyrus
You can absolutely combine the two projects. However, I would encourage you to look at Spring-MVC for doing REST as it is very powerful and easy to use. If memory serves, the jersey-spring project was helpful in integration of JAXB and other touch points. Again, this is all built into Spring. And if you use Spring-Boot it is amazingly simple to get running.
The jersey-spring project provides integration between Jersey and Spring. It allows you to wire in any beans in your Spring context into Jersey and vice-versa.
For instance, if you are using spring-security, it will provide your spring-security principal when wiring the Jersey specific SecurityContext into any of your REST resources.
If you want to access Spring beans from your Jersey REST endpoints (or use Spring Beans as implementations for your JAX-RS interfaces) you need to integrate Spring and Jersey, otherwise it won't work. If you don't have any connections between Spring beans and your REST endpoints, then it is not necessary.
I think your first statement is correct. I have used Jersey and Sprint as separate entities.
Jersey is really awesome to create a web server.
Spring is useful for dependency injection (beans) and other cools stuff.
About your second statement, I do not know anything jersey-spring maven project.
My suggestion/opinion is to do as your first comment. Use them in a separate way. You will have the best of both worlds. Using jersey-spring maven project might be a complication and maybe it is not what you want. Libraries usually are intend to be independent.

JSF 1.2 + Spring 2.5. How to?

I am using Spring to manage my DAO & Services. And JSF for UI. I want to use dependency injection in my JSF backing-bean. There is an article that explained how I can do that.
But I have two separate projects: one for Service and one for UI. The Spring configuration file is located in Service project.
How can I connect both project with Spring? I want to annotate my JSF pages for DI.
You can achieve this by using Spring Web Flow.
Spring have examples which show:
A JSF centric approach where your Spring and JSF beans are managed/configured the JSF way (faces-config) and a
Spring centric approach where your beans (including ManagedBeans) are managed in the Spring Context.
See Spring Flow Web Home
If you mean that you have one WAR with web services defined in it, and another separate WAR with the JSF stuff, I think it's really two separate projects each with their own Spring configuration.
The web service WAR will use either Spring web services or perhaps HTTP remoting to expose your service interfaces to clients via HTTP. This will have one set of application context configuration, either XML or annotations.
The JSF WAR will have the JSPs and controllers. The controllers will be injected with clients that will interact with the remote services to accomplish what you wish. That's all they need to know about the service WAR. There doesn't need to be any duplication of configuration at all.
It's actually a nice design, because it completely decouples the view from the rest of the problem.
Thank for everyone I did it. My mistake was with bean initialization. I tried to access my injected bean in constructor, but must must did in #PostConstruct method. And all that time i tried to find mistake in my config file. But it was in such simply place :)
I find some solution one:
Sample Application using JSF, Spring 2.5, and Java Persistence APIs with Glassfish v2
. But I have problem with it.
I can post this problem hear or must create new topic? Sorry for stupid question, i'm newbie her.

Categories

Resources