0

I configured Spring MVC with apache Tiles.

 <context:component-scan base-package="controllers"/>

<!--<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">-->
    <!--<property name="prefix" value="/WEB-INF/pages/"/>-->
    <!--<property name="suffix" value=".jsp"/>-->
<!--</bean>-->

<bean id="tilesConfigure" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/tailesconfig/general.xml</value>
        </list>
    </property>
</bean>

<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView"/>
</bean>



<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />

Inside the controller I want to return Json object.

public class Greeting {

    private final long id;
    private final String content;

    public Greeting(long id, String content) {
        this.id = id;
        this.content = content;
    }

    public long getId() {
        return id;
    }

    public String getContent() {
        return content;
    }
}

private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();

@RequestMapping(value = "/greeting",produces = "application/json")
public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
    return new Greeting(counter.incrementAndGet(),
            String.format(template, name));
}

}

But when i requesting http://localhost:8081/greeting , i get : Could not resolve view with name 'greeting' in servlet with name 'mvc-dispatcher' Sorry for my English and thanks for any help!

Denis Markov
  • 309
  • 4
  • 12

1 Answers1

0

look into spring's ContentNegotiatingViewResolver

mck
  • 1,152
  • 10
  • 10