i'm having trouble configuring dispatcher spring. trying achieve is:
- build rest webservice receive requests
- have html + ajax pages consuming data (therefore, don't have views in spring project)
so far have 2 html pages: login (using j_security_check) , main page. both simple. have simple controller:
maincontroller.java
@restcontroller //or @controller , @responsebody, no difference, right? public class maincontroller { @requestmapping("rest/main/data") public string getdata () { return "{data: \"data huehue\"}"; // yes, i'm brazilian } }
and have tried following configuration web.xml , dispatcher-servlet.xml:
web.xml:
<servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping>
dispatcher-servlet.xml
<context:component-scan base-package="com.example.controller"/>
this doesn't work. message info: mapped url path [/rest/main/data] onto handler 'maincontroller'
when try access no mapping found http request uri [/myapp/rest/main/data] in dispatcherservlet name 'dispatcher'
i have tried:
- on web.xml:
<url-pattern>/</url-pattern>
- on dispatcher-servlet: same
- what happened: controller did work application tried map login.html , couldnt find match got 404 ;-;
i'm aware of "standard" configuration using prefix , sufix, since dont have views here dont think that's right approach. i'm kinda new @ spring (as may have noticed), please gentle on answers.
any ideas?
thanks in advance :)
my project tree:
-project --src ---main ----webapp -----web-inf ------web.xml ------weblogic.xml ------dispatcher-servlet.xml -----www ------main.html -----login.html
(login outside www)
with first approach if modify controller code have /rest/main/data
work.
@restcontroller //or @controller , @responsebody, no difference, right? public class maincontroller { @requestmapping("/rest/main/data") public string getdata () { return "{data: \"data huehue\"}"; // yes, i'm brazilian } }
what happening in happening in second approach since have spring security configured need authenticated first finds login.html , can not find it. may because of incorrect configuration.