I cannot access Robots.txt in Spring-MVC
Asked Answered
B

1

3

I am trying to give access to robots.txt in Spring-MVC. To test the code, I put robots.txt in WebContent,Root and WEB-INF but I cannot access to any of them.

I've already applied answers of these questions 1,2,3 to no avail.

MyCode

<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:resources mapping="/robots.txt" location="/robots.txt" order="0" />
<mvc:annotation-driven />
Bridgeboard answered 31/8, 2015 at 0:18 Comment(3)
Put it in webapp Do you have Spring Security setup?Comb
@NeilMcGuigan No I do not have that setup.Bridgeboard
@NeilMcGuigan If I put that in webapp how to give access to that? do I need to configure anything in my Spring application or Tomcat? I have a test.jsp file in my root folder which I can access but not this robots.txt file.Bridgeboard
C
3

This works for me:

Put robots.txt directly under webapp

In mvc-dispatcher-servlet.xml have:

<mvc:default-servlet-handler/>

<mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/web-resources/" />

Use maven to build your war

Comb answered 1/9, 2015 at 3:42 Comment(2)
would robots.txt be available on www.domain.com/robots.txt? does that mean you are mapping /resources/** to two different locations? / and /Meta-INF/.... ?Bridgeboard
Hi, how to configure the same using Java configs instead of xml configs? Thanks.Wiseacre

© 2022 - 2024 — McMap. All rights reserved.