如何更改错误无法调用Tomcat管理器:服务器返回HTTP响应代码:403

时间:2014-03-31 04:53:18

标签: java spring maven tomcat spring-mvc

运行java-thymeleaf-maven-spring应用程序时出错

这里使用的是tomcat7。

此处显示步骤

  1. 从git-hub下载项目

  2. mvn clean install显示Build Success

  3. mvn tomcat:部署构建失败

  4. 并显示错误

    [错误]无法执行目标org.codehaus.mojo:tomcat-maven-plugin:1.1:deploy 项目spring-mvc-thymeleaf上的(default-cli):无法调用Tomcat管理器:服务器返回HTTP响应代码:403为URL:http://localhost:8080/manager/deploy?path=%2Fspring-mvc-thymeleaf&war= - > [帮助1]

    这里下载了很多程序,所有程序都显示了这个问题

    其中一个程序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>net.exacode.bootstrap</groupId>
        <artifactId>spring-mvc-thymeleaf</artifactId>
        <packaging>war</packaging>
        <name>spring-mvc-thymeleaf</name>
        <version>0.0.1-SNAPSHOT</version>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <maven.compiler.source>1.7</maven.compiler.source>
            <maven.compiler.target>1.7</maven.compiler.target>
            <!-- Dependency version -->
            <spring.version>3.1.0.RELEASE</spring.version>
            <slf4j.version>1.6.4</slf4j.version>
            <!-- Spring profile -->
            <spring.profiles.active>development</spring.profiles.active>
        </properties>
    
        <dependencies>
            <!-- Logging dependencies -->
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
                <version>1.0.1</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-api</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>${slf4j.version}</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>jcl-over-slf4j</artifactId>
                <version>${slf4j.version}</version>
            </dependency>
            <dependency>
                <groupId>org.thymeleaf</groupId>
                <artifactId>thymeleaf-spring3</artifactId>
                <version>2.0.13</version>
            </dependency>
            <!-- Spring dependencies -->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <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>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-validator</artifactId>
                <version>4.3.1.Final</version>
            </dependency>
            <dependency>
                <groupId>nz.net.ultraq.web.thymeleaf</groupId>
                <artifactId>thymeleaf-layout-dialect</artifactId>
                <version>1.0.5</version>
            </dependency>
            <!--We need servlet API for compiling the classes. Not needed in runtime -->
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <version>3.0.1</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>cglib</groupId>
                <artifactId>cglib</artifactId>
                <version>2.2.2</version>
            </dependency>
        </dependencies>
    
        <build>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
        </build>
    </project>
    

    以及该计划https://github.com/mendlik/spring-mvc-thymeleaf

    的链接

    我在谷歌搜索此错误但我无法找到程序方面的任何问题。

    tomcat用户文件显示,

    <role rolename="tomcat"/>
      <role rolename="role1"/>
      <user username="tomcat" password="tomcat" roles="tomcat"/>
      <user username="both" password="tomcat" roles="tomcat,role1"/>
      <user username="role1" password="tomcat" roles="role1"/>
    

1 个答案:

答案 0 :(得分:1)

你有没有在你的pom.xml中加入maven tomcat插件?你的pom的构建部分应该像:

<build>
   <resources>
      <resource>
          <directory>src/main/resources</directory>
          <filtering>true</filtering>
          </resource>
   </resources>
   <plugins>
      <!-- Maven Tomcat Plugin -->
      <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>tomcat-maven-plugin</artifactId>
    <configuration>
        <url>http://127.0.0.1:8080/manager</url>
        <server>TomcatServer</server>
        <path>/mkyongWebApp</path>
    </configuration>
       </plugin>
    <plugins>
</build>

您还必须为Tomcat添加具有管理员访问权限的用户。编辑文件 - “%TOMCAT_PATH%/ conf / tomcat-users.xml”并为用户tomcat添加角色管理器。

<role rolename="tomcat"/>
  <role rolename="role1"/>
  <role rolename="manager"/>
  <user username="tomcat" password="tomcat" roles="tomcat,manager"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="role1" password="tomcat" roles="role1"/>