i'm trying to make some REST services with a JBOSS AS7 but when I try to access them the logs says 404.
I been looking for solutions but doesn't found the solution.
The services are in a WAR project, which is in a EAR file to make the deploy in the JBOSS.
I'm using CXF and CDI to make the services.
The JBOSS has the version 3.0.5 of EasyRest.
This is the pom.xml of the WAR project:
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>projectParent</groupId>
<artifactId>projectParent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>projectParent</groupId>
<artifactId>projectWARModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>projectWARModule Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.apache.cxf.version>3.0.0</org.apache.cxf.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-integration-cdi</artifactId>
<version>${org.apache.cxf.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api -->
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${org.apache.cxf.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-rt-wsdl -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-wsdl</artifactId>
<version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-rt-ws-policy -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-policy</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<version>2.1.2.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core</artifactId>
<version>2.1.2.Final</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<url>http://download.java.net/maven/2/</url>
</repository>
<repository>
<id>jboss-public</id>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
</repositories>
<build>
<finalName>projectWAR</finalName>
</build>
</project>
This is the pom.xml of the EAR package, it have a reference to a JAR because in a tutorial I found about making EAR with maven it says to use it, but doesn't have anything:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>projectParent</groupId>
<artifactId>projectParent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>projectEARModule</artifactId>
<packaging>ear</packaging>
<dependencies>
<dependency>
<groupId>projectParent</groupId>
<artifactId>projectJARModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>projectParent</groupId>
<artifactId>projectWARModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<finalName>projectEar</finalName>
</build>
</project>
This class is named PeopleRestService and have the services:
package com.example.rs;
import java.util.Collection;
import javax.inject.Inject;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import com.example.model.Person;
import com.example.services.PeopleService;
#Path( "/people" )
public class PeopleRestService {
#Inject private PeopleService peopleService;
#Produces( { MediaType.APPLICATION_JSON } )
#GET
public Collection< Person > getPeople( #QueryParam( "page") #DefaultValue( "1" ) final int page ) {
return peopleService.getPeople( page, 5 );
}
#Produces( { MediaType.APPLICATION_JSON } )
#Path( "/{email}" )
#GET
public Person getPerson( #PathParam( "email" ) final String email ) {
return peopleService.getByEmail( email );
}
#Produces( { MediaType.APPLICATION_JSON } )
#POST
public Response addPerson( #Context final UriInfo uriInfo,
#FormParam( "email" ) final String email,
#FormParam( "firstName" ) final String firstName,
#FormParam( "lastName" ) final String lastName ) {
final Person person = peopleService.addPerson( email, firstName, lastName );
return Response.created( uriInfo.getRequestUriBuilder().path( email ).build() ).entity( person ).build();
}
#Produces( { MediaType.APPLICATION_JSON } )
#Path( "/{email}" )
#PUT
public Person updatePerson(
#PathParam( "email" ) final String email,
#FormParam( "firstName" ) final String firstName,
#FormParam( "lastName" ) final String lastName ) {
final Person person = peopleService.getByEmail( email );
if( firstName != null ) {
person.setFirstName( firstName );
}
if( lastName != null ) {
person.setLastName( lastName );
}
return person;
}
#Path( "/{email}" )
#DELETE
public Response deletePerson( #PathParam( "email" ) final String email ) {
peopleService.removePerson( email );
return Response.ok().build();
}
}
And this is named JaxRsApiApplication:
package com.example.rs;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
#ApplicationPath( "api" )
public class JaxRsApiApplication extends Application {
}
This is the beans.xml:
<?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://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all">
</beans>
And this is the 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>Archetype Created Web Application</display-name>
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.providers</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.resources</param-name>
<param-value>false</param-value>
</context-param>
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
<servlet>
<servlet-name>PeopleRestService</servlet-name>
<servlet-class>org.apache.cxf.cdi.CXFCdiServlet</servlet-class>
<init-param>
<param-name>org.apache.cxf.cdi</param-name>
<param-value>com.example.rs</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>PeopleRestService</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
When I try run this in a tomcat works perfectly, but in JBOSS only get a 404.
I think could be a problem with the libraries, but don't know what problem especificaly.
If anyone know what could be happening it would be a great help.
Thank you very much and sorry if my english is bad.
Have a nice day.
UPDATE
As #JanezKuhar says I reemplace the imports in the pom. Now the dependencies looks like:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<!-- <dependency> -->
<!-- <groupId>javax.enterprise</groupId> -->
<!-- <artifactId>cdi-api</artifactId> -->
<!-- <version>1.1</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.apache.cxf</groupId> -->
<!-- <artifactId>cxf-integration-cdi</artifactId> -->
<!-- <version>${org.apache.cxf.version}</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.apache.cxf</groupId> -->
<!-- <artifactId>cxf-rt-frontend-jaxrs</artifactId> -->
<!-- <version>${org.apache.cxf.version}</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>javax.annotation</groupId> -->
<!-- <artifactId>javax.annotation-api</artifactId> -->
<!-- <version>1.2</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.apache.cxf</groupId> -->
<!-- <artifactId>cxf-rt-transports-http</artifactId> -->
<!-- <version>${org.apache.cxf.version}</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.apache.cxf</groupId> -->
<!-- <artifactId>cxf-rt-wsdl</artifactId> -->
<!-- <version>3.0.0</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.apache.cxf</groupId> -->
<!-- <artifactId>cxf-rt-ws-policy</artifactId> -->
<!-- <version>3.0.0</version> -->
<!-- </dependency> -->
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.2.3</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.jboss.weld.servlet</groupId> -->
<!-- <artifactId>weld-servlet</artifactId> -->
<!-- <version>2.1.2.Final</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.jboss.weld</groupId> -->
<!-- <artifactId>weld-core</artifactId> -->
<!-- <version>2.1.2.Final</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>javax.inject</groupId> -->
<!-- <artifactId>javax.inject</artifactId> -->
<!-- <version>1</version> -->
<!-- </dependency> -->
</dependencies>
But it gives me now the following error:
Caused by: java.lang.ClassNotFoundException: org.apache.cxf.cdi.CXFCdiServlet from [Module "deployment.projectEar.ear.projectWARModule-0.0.1-SNAPSHOT.war:main" from Service Module Loader]
Finaly make this works.
As #JanezKuhar says I comment all the extra libraries in the pom and added two, now looks like this:
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>projectParent</groupId>
<artifactId>projectParent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>projectParent</groupId>
<artifactId>projectWARModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>projectWARModule Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.apache.cxf.version>3.0.0</org.apache.cxf.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf</artifactId>
<version>3.0.0</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<version>2.1.2.Final</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<url>http://download.java.net/maven/2/</url>
</repository>
<repository>
<id>jboss-public</id>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
</repositories>
<build>
<finalName>projectWAR</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
<archive>
<manifestEntries>
<Dependencies>org.apache.cxf.impl</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Comment the servlet part and set the restEasy scan true, in the 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>Archetype Created Web Application</display-name>
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.providers</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.resources</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
</web-app>
Now it works and I can access the REST servicies deployed in the jboss.
Thanks for the help provided.
Where is your jboss-app.xml? Does maven create it?
In jboss-app.xml you (or maven) should create context root of your application.
jboss-app.xml: Every EAR application should specify a unique string name for the class loader. It's from JBoss doc. link
Related
I have an old (inherited) project that I need to deploy on AWS but I get some problems related to the template folder.
This project has an index.xhtml on "src\main\webapp" instead of "src\main\resources\templates", I think it is beacuse it uses jsf but I'm new on Springboot and jsf pages.
In the documentation I've got it says that in order to open the web you need to visit http://localhost:5000/index.jsf so to solve it I made a class with
#Controller
public class IndexController {
#RequestMapping(value = {"", "/"})
public String index() {
return "redirect:/index.jsf";
}
}
In local works but the problem I get is that when I deploy it on AWS with Elastic Beanstalk, I create a new Java application on it to upload the jar file made with maven.
But when I enter to the application I always get this message:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Jun 18 14:52:25 UTC 2020
There was an unexpected error (type=Not Found, status=404).
/index.jsp
I try to:
Search where it's configured the custom folder but I didn't find it.
Move the index.xhtml file to templates but doesn't work.
Add to application.properties file spring.thymeleaf.prefix=classpath:/templates/ to set the default folder.
Instead of Java application I made a Tomcat application on Elastic Beanstalk and upload a war file made with maven but I get a tomcat 404.
The project has a page on swagger-ui to test de API Rest petitions, I don't know if it might cause some problems.
POM.XML
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>es.xxxxxxx</groupId>
<artifactId>xxxxxxxxxx</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>xxxxxxxxxx</name>
<description>xxxxxxxxxxxxxxxxxxxxxxx</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>compile</scope>
</dependency>
<!-- JSF -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.8-02</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.8-02</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.3</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hppc</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-json-org</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.10</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
<layout>default</layout>
</repository>
</repositories>
</project>
application.properties
server.port = 5000
More Info:
I noticed that the WEB-INF folder was missing so I created it (also clasess and lib folders) and I added these files.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="3.1">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
</web-app>
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
</faces-config>
Besides I added this line on pom.xml
<outputDirectory>src/main/webapp/WEB-INF/classes</outputDirectory>
But the problem continues.
I have created a simple helloWorld maven dependency and placed that in my springmvc projects pom.xml but while deploying its showing bean creation exception of that helloWorld: not a qualified bean.
Any help would be appreciated. Thank you.
Here how my dependent project looks like
My Application.java
package com.test
#Configuration
#EnableAutoConfiguration
#ComponentScan({"com.test"})
#EnableTransactionManagement
public class Application {
public static void main(String[] args) {
System.out.println("hai");
SpringApplication app = new SpringApplication(Application.class);
app.run(args);
}
}
My Controller
package com.test.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import test.Application;
import test.controller.Check;
#RestController
#RequestMapping("/Rest")
public class Controller {
#Autowired
Check check; // this is the bean from that dependency
#RequestMapping(value="/logs",method=RequestMethod.GET)
public String logs(){
return "I am the controler";
}
}
My pom.xml
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>waffleTalentpool</groupId>
<artifactId>waffleTalentpool</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<properties>
<java.version>1.8</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>server-api</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>com.github.dblock.waffle</groupId>
<artifactId>waffle-jna</artifactId>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.github.dblock.waffle</groupId>
<artifactId>waffle-tomcat8</artifactId>
<version>1.7.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<artifactId>logback-classic</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
<exclusion>
<artifactId>log4j-over-slf4j</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
**<dependency>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>** // This is my maven dependency for standalone java application
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.10-FINAL</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.10-FINAL</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
My web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>waffleTalentpool</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>TP</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.test.Application</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>TP</servlet-name>
<url-pattern>/tp/*</url-pattern>
</servlet-mapping>
</web-app>
My source code link
here
Your project structure does not follow maven standards.I updated the structure and uploaded here. Please try and let me know if that works
https://drive.google.com/file/d/0B3qylcHD3O-ddjVJLXRuOF9zM1U/view?usp=sharing
I'm trying to initialize the StanfordCoreNLP at the startup of my Jersey 2 webapp.
I found out, that ServletContextListener is the way to do it but i don't have ServletContextListener in jersey 2 right?
So how can i load this code on startup of my jersey 2 webapp:
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
Edit
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<web-app version="2.5" 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/web-app_2_5.xsd">
<servlet>
<servlet-name>com.crawler.c_api.rest.ApplicationResource</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.crawler.c_api</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>com.crawler.c_api.provider.ResponseCorsFilter;org.glassfish.jersey.filter.LoggingFilter</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>com.crawler.c_api.rest.ApplicationResource</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
pom.xml
<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>com.crawler</groupId>
<artifactId>C_API</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>C_API</name>
<build>
<finalName>C_API</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP-java6</artifactId>
<version>2.2.5</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.mindrot</groupId>
<artifactId>jbcrypt</artifactId>
<version>0.3m</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>com.syncthemall</groupId>
<artifactId>boilerpipe</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.5.2</version>
<classifier>models</classifier>
</dependency>
</dependencies>
<properties>
<jersey.version>2.19</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
ApplicationResource
package com.crawler.c_api.rest;
import com.crawler.c_api.provider.ResponseCorsFilter;
import java.util.logging.Logger;
import org.glassfish.jersey.filter.LoggingFilter;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.ServerProperties;
public class ApplicationResource extends ResourceConfig {
private static final Logger LOGGER = null;
public ApplicationResource() {
System.out.println("iansdiansdasdasd");
// Register resources and providers using package-scanning.
packages("main.java.com.crawler.c_api");
// Register my custom provider - not needed if it's in my.package.
register(ResponseCorsFilter.class);
// Register an instance of LoggingFilter.
register(new LoggingFilter(LOGGER, true));
// Enable Tracing support.
property(ServerProperties.TRACING, "ALL");
}
}
ServletContextListener if part of the Servlet APIs. So you can just add
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
But it might not be necessary. There are more ways to deploy a Jersey app aside from just a web.xml. You can extend a ResourceConfig. This will allows you to go completely xml-less even if you wanted to. Everything you configure in the web.xml, for the most part can be configured in the ResourceConfig.
You could even use both web.xml and a ResourceConfig. For example
public class MyApplication extends ResourceConfig {
public MyApplication() {
packages("org.foo.rest;org.bar.rest");
// do any other initialization here
}
}
<web-app>
<servlet>
<servlet-name>org.foo.rest.MyApplication</servlet-name>
</servlet>
...
<servlet-mapping>
<servlet-name>org.foo.rest.MyApplication</servlet-name>
<url-pattern>/resources</url-pattern>
</servlet-mapping>
...
</web-app>
See other deployment options here. There are a few different ways to deploy an Jersey app.
I checked the headers and made sure I had Accept:application/json
I'm not sure why Spring is still reporting a 406, I can consume MVC controllers fine.
I looked and made sure I had all the right includes in Maven, so that shouldn't be the issue. I'm running Tomcat 8, and Java 8.
Any help would be appreciated!
RestUtilityController
package io.bray.springtest;
import java.util.List;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.persistence.*;
#RestController
public class RestUtilityController {
private static EntityManager em = Persistence.createEntityManagerFactory("SpringTest").createEntityManager();
#RequestMapping(value="/emailExists", produces="application/json")
#ResponseBody
public Boolean loginConfirmation(#RequestParam("email") String email){
List logins = em.createQuery("SELECT l FROM LoginDto l WHERE l.email = :email").setParameter("email", email).getResultList();
if(logins.size() > 0){
return new Boolean(true);
}
return new Boolean(false);
}
}
pom.xml
<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>SpringTest</groupId>
<artifactId>SpringTest</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Spring 2 MVC</name>
<properties>
<jdk.version>1.6</jdk.version>
<spring.version>4.2.0.RELEASE</spring.version>
<jstl.version>1.2</jstl.version>
<servletapi.version>2.5</servletapi.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<!-- Spring MVC framework -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<!-- for compile only, your container should have this -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servletapi.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.2.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<!-- embedded jetty, good for testing -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.11.v20150529</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webApp>
<contextPath>/spring2</contextPath>
</webApp>
</configuration>
</plugin>
<!-- configure Eclipse workspace -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<wtpversion>2.0</wtpversion>
<wtpContextName>spring2</wtpContextName>
</configuration>
</plugin>
</plugins>
</build>
</project>
web.xml
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring Web MVC Application</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
mvc-dispatcher-servlet.xml
<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-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd"
xmlns:context = "http://www.springframework.org/schema/context">
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<context:annotation-config/>
<context:component-scan base-package="io.bray.springtest"/>
</beans>
I keep getting a NoSuchBeanDefinitionException in my service layer and I have no idea why, any help will be appreciated. This is out of spring in action book, the spitter app. Am i missing something. I am trying to build it myself using maven instead of gradle.
Exception:
org.springframework.beans.factory.BeanCreationException: Error creating bean witlerMapping#0': Initialization of bean failed;
nested exception is org.springfram name 'homeController' defined in file [/data/TOMCAT-6.0/apache-tomcat-6.0.33/wess]: Unsatisfied dependency expressed through constructor argument with index 0 of type [com.john.springinaction.service.SpitterService] found for dependency: ndency. Dependency annotations: {};
nested exception is org.springframework.beanspringinaction.service.SpitterService] found for dependency: expected at least 1annotations: {}
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBe
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
at org.springframework.beans.factory.support.DefaultListableBeanFactory.
at org.springframework.context.support.AbstractApplicationContext.finish
at org.springframework.context.support.AbstractApplicationContext.refres
at org.springframework.web.servlet.FrameworkServlet.createWebApplication
at org.springframework.web.servlet.FrameworkServlet.createWebApplication
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationCo
at org.springframework.web.servlet.FrameworkServlet.initServletBean(Fram
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.jav
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:48
at java.lang.Thread.run(Thread.java:619)
Controller:
package com.john.springinaction.mvc;
import java.util.Map;
import javax.inject.Inject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.john.springinaction.service.SpitterService;
#Controller
public class HomeController {
public static final int DEFAULT_SPITTLES_PER_PAGE = 25;
#Autowired
private SpitterService spitterService;
#RequestMapping({"/","/home"})
public String showHomePage(Map<String, Object> model) {
model.put("spittles",
spitterService.getRecentSpittles(DEFAULT_SPITTLES_PER_PAGE));
return "home";
}
}
Service:
package com.john.springinaction.service;
import static java.lang.Math.min;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.john.springinaction.domain.Spitter;
import com.john.springinaction.domain.Spittle;
import com.john.springinaction.persistence.SpitterDAO;
#Service("spitterService")
#Transactional(propagation = Propagation.REQUIRED)
public class SpitterServiceImpl implements SpitterService {
#Autowired
private SpitterDAO spitterDAO;
#Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
public List<Spittle> getRecentSpittles(int count) {
List<Spittle> recentSpittles =
spitterDAO.getRecentSpittle();
return recentSpittles.subList(0, min(49, recentSpittles.size()));
}
public void saveSpittle(Spittle spittle) {
spittle.setWhen(new Date());
spitterDAO.saveSpittle(spittle);
}
#Transactional(propagation=Propagation.SUPPORTS, readOnly=false)
public void saveSpitter(Spitter spitter) {
if (spitter.getId() == null) {
spitterDAO.addSpitter(spitter);
}else {
spitterDAO.saveSpitter(spitter);
}
}
#Transactional(propagation=Propagation.SUPPORTS, readOnly=false)
public void deleteSpitter(Spitter spitter) {
spitterDAO.deleteSpitter(spitter);
}
#Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public Spitter getSpitter(long id) {
return spitterDAO.getSpitterById(id);
}
public void startFollowing(Spitter follower, Spitter followee) {
}
public List<Spittle> getSpittlesForSpitter(Spitter spitter) {
return spitterDAO.getSpittlesForSpitter(spitter);
}
public List<Spittle> getSpittlesForSpitter(String username) {
return spitterDAO.getSpittlesForSpitter(username);
}
public Spitter getSpitter(String username) {
return spitterDAO.getSpitterByUsername(username);
}
public Spittle getSpittleById(long id) {
return spitterDAO.getSpittleById(id);
}
public void deleteSpittle(long id) {
spitterDAO.deleteSpittle(id);
}
public List<Spitter> getAllSpitters() {
return null;
}
}
beanlocations.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: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://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">
<!-- Database Configuration -->
<import resource="DataSource.xml"/>
<import resource="Hibernate.xml"/>
<import resource="Service.xml"/>
<!-- Auto scan the components -->
<context:component-scan base-package="com.john.springinaction" />
<context:annotation-config/>
</beans>
hibernate.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:tx="http://www.springframework.org/schema/tx"
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/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.john.springinaction.service" />
<tx:annotation-driven/>
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.4"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<!-- context load listener -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- <listener>
<listener-class>org.apache.tiles.web.startup.TilesListener</listener-class>
</listener> -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:*BeanLocations.xml
</param-value>
</context-param>
<servlet>
<servlet-name>spitter</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spitter</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
pom.xml
<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>com.john.springinaction</groupId>
<artifactId>Spitter</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Spitter</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>JBoss repository</id>
<url>http://repository.jboss.com/maven2/</url>
</repository>
</repositories>
<properties>
<spring.version>3.0.5.RELEASE</spring.version>
</properties>
<dependencies>
<!-- Test Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<!-- Spring framework -->
<!-- <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency> -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>
<!-- Spring AOP Dependency -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
</dependency>
<!-- Spring MVC framework -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- MySQL database driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>
<!-- Hibernate framework -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.3.2.GA</version>
</dependency>
<!-- Hibernate annotation -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.4.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.3.0.ga</version>
</dependency>
<!-- Hibernate library dependecy start -->
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<!-- Hibernate library dependecy end -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.glassfish.v3.osgi</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.1.5</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<outputDirectory>target/artefacts/wars</outputDirectory>
<warName>spitter</warName>
</configuration>
</plugin>
</plugins>
</build>
</project>
It seems that you might have SpitterService in different packages. Try to specify which one you want exactly in the controller by either:
#Autowired
#Qualifier( "spitterService" )
private SpitterService spitterService;
or
#Resource( name="spitterService" )
private SpitterService spitterService;
i think u have not written the other necessary classes and interfaces, like Spitter, Spittle, and other service classes please create those classes first