0
votes

Im a newbie with jersey web-service framework, so I tried to build up a project with a little tutorial help.

The server works fine, but I cant inject any component.. I tried to inject the wfExampleDao, but in the begining of the tomcat log says

SEVERE: None or multiple beans found in Spring context for type class hu.example.MenuController, skipping the type.

so the tomcat says to me, that injection will be skipped.. My first clue, that web-service can not find the applicationContext.xml. But I dont know why, because In my other projects the contextConfigLocation is enough.

Actually I did not find a good tutorial with the next parameters: jersey, spring, gradle

Has anybody any idea, whats wrong, or can you show me a good example?

Thanks in advance!

My build.gradle looks like this:

apply plugin: 'java'
apply plugin: "war"
apply plugin: "eclipse-wtp"



repositories {
    maven {
        url "https://jcenter.bintray.com"
    }
}


sourceCompatibility = "1.8"
targetCompatibility = "1.8"
compileJava.options.encoding = 'UTF-8'
version = '0.1.0'

dependencies {
    compile 'org.glassfish.jersey.ext:jersey-spring3:2.19'
    compile 'org.springframework:spring-web:4.3.10.RELEASE'

    compile 'commons-dbcp:commons-dbcp:1.4'
    compile 'commons-pool:commons-pool:1.6'


    testCompile 'junit:junit:4.12'
}

My web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">

    <display-name>webservice</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>

    <!--configure Spring as annotation driven and java config -->
    <context-param>
      <param-name>contextClass</param-name>
      <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
    </context-param>
    <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- configure the Jersey-Sring servlet -->
    <servlet>
        <servlet-name>RestuarantApplication</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
          <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>hu.example.configuration.JerseyApplication</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>RestuarantApplication</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
<context-param>
    <param-name>webservice.properties.location</param-name>
    <param-value>etc/opt/webservice</param-value>
</context-param>

</web-app>

finally my applicationContext.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.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

    <context:annotation-config />

    <context:component-scan base-package="hu.example" />

    <bean id="conversionService"
        class="org.springframework.context.support.ConversionServiceFactoryBean" />


    <bean id="propertyConfigurer"
        class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
        <property name="fileEncoding" value="UTF-8" />
        <property name="locations">
            <list>
                <!-- ${webservice.properties.location} is set in web.xml, defaults to 
                    /etc/opt/webservice -->
                <value>classpath:version.properties</value>
                <value>file:///${webservice.properties.location}/jdbc.properties</value>
            </list>
        </property>
    </bean>

    <bean id="oracleDataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <property name="validationQuery" value="${jdbc.validationQuery}" />
    </bean> 

    <bean id="wfExampleDao" class="hu.example.dao.WfExampleDaoImpl">
        <property name="dataSource" ref="oracleDataSource" /> 
    </bean>  
</beans>
1

1 Answers

1
votes

You are scanning for "hu.example" package for beans and it appears as though one of your annotated bean is trying to load the bean "hu.example.MenuController" and either cannot find it, ie that class is not annotated as a bean or spring is able to find more than one bean and is unable to determine which one to load. Hope this helps