代码之家  ›  专栏  ›  技术社区  ›  sofs1 Romain Manni-Bucau

为什么我的pom。xml在最终的war构建中不包含或生成类文件?

  •  -4
  • sofs1 Romain Manni-Bucau  · 技术社区  · 6 年前

    弹簧安全。xml

    <?xml version="1.0" encoding="UTF-8"?>
    <b:beans xmlns="http://www.springframework.org/schema/mvc"
        xmlns:b="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" 
        xmlns:security="http://www.springframework.org/schema/security"
        xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
            http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
    
        <tx:annotation-driven transaction-manager="transactionManager"/> 
        <b:bean class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler"/>
    
        <security:http auto-config='true' use-expressions='true'>
             <security:form-login login-page="/login" default-target-url="/loginSuccess" 
                authentication-failure-url="/home?authfailed=true" 
                username-parameter="mobileNumber"
                password-parameter="password"
                always-use-default-target="true"/> 
              <security:intercept-url pattern="/loginCheck" access="hasRole('VERIFIED_USER')"/>
              <security:intercept-url pattern="/loginSuccess" access="hasAuthority('ROLE_VERIFIED_USER')"/>
              <security:intercept-url pattern="/home" access="permitAll" />
              <security:intercept-url pattern="/News" access="permitAll" />
    
              <security:logout invalidate-session="true" logout-url="/logout"/>          
        </security:http>
    
           <security:authentication-manager erase-credentials="false">
                <security:authentication-provider ref="myAuthenticationProvider">
                </security:authentication-provider> 
           </security:authentication-manager> 
    
    
        <b:bean id="bcryptEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder" />
    
        <b:bean id="myAuthenticationProvider" class="com.ct.www.provider.CustomAuthenticationProvider">
        </b:bean>   
    
        <security:global-method-security secured-annotations="enabled"/>
    
        <b:bean id="personService" class="com.ct.www.service.PersonServiceImpl">
            <b:property name="personDAO" ref="personDAO"></b:property>
        </b:bean>
    
        <b:bean id="personDAO" class="com.ct.www.dao.PersonDAOImpl">
            <b:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" />
        </b:bean> 
    
        <b:bean id="articleService" class="com.ct.www.service.ArticleServiceImpl">
            <b:property name="articleDAO" ref="articleDAO"></b:property>
        </b:bean>
    
        <b:bean id="articleDAO" class="com.ct.www.dao.ArticleDAOImpl">
            <b:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" />
        </b:bean> 
    <!-- For hashing and salting user passwords -->
        <b:bean id="encoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"/>   
    
    <!--     <b:bean id="basicAuthenticationFilter" class="org.springframework.security.web.authentication.www.BasicAuthenticationFilter">
            <b:constructor-arg ref="authenticationManager" />
             <b:constructor-arg ref="authenticationEntryPoint" />
    
        </b:bean> -->
    
        <!--  <b:bean id="authenticationEntryPoint" 
            class="com.ct.www.provider.PlainTextBasicAuthenticationEntryPoint">
            <b:property name="realmName" value="http://localhost:8080" />
        </b:bean> 
         -->
      <b:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
            destroy-method="close">
            <b:property name="driverClassName" value="com.mysql.jdbc.Driver" /> 
            <b:property name="url" value="jdbc:mysql://22.66.111.44:3306/ct?autoReconnect=true&amp;characterEncoding=utf8" />
            <b:property name="username" value="root" />
            <b:property name="password" value="pwd" />
      </b:bean>
    
    
        <!--  Form Validator -->
    
        <b:bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
            <b:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" />
        </b:bean> 
    
    
        <!-- Hibernate 4 SessionFactory Bean definition -->
        <b:bean id="hibernate4AnnotatedSessionFactory"
            class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
            <b:property name="dataSource" ref="dataSource" />
            <b:property name="packagesToScan">
                <b:list>
                    <b:value>com.ct.www.model</b:value>
                </b:list>
            </b:property>
            <b:property name="hibernateProperties">
                <b:props>
                    <b:prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect
                    </b:prop>
                    <b:prop key="hibernate.show_sql">true</b:prop>
                </b:props>
            </b:property>
        </b:bean>
    
        <context:component-scan base-package="com.ct.www" /> 
    
        <annotation-driven />
    
    <!--    Handles HTTP GET requests for /resources/** by efficiently serving 
            up static resources in the ${webappRoot}/resources directory -->
        <resources mapping="/resources/**" location="/resources/" />
    
        <!-- Resolves views selected for rendering by @Controllers to .jsp resources 
            in the /WEB-INF/views directory -->
        <!-- <b:bean
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <b:property name="prefix" value="/WEB-INF/views/" />
            <b:property name="suffix" value=".jsp" />
        </b:bean>     -->
    
    </b:beans>
    

    enter image description here

    网状物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" version="3.0">
      <!-- the purpose of context-param element is to define "context initialization parameters" that is available to all servlets in the web app -->
      <context-param>
        <param-name>contextConfigLocation</param-name>
         <param-value>classpath:/spring/appServlet/spring-security.xml</param-value>
      </context-param>
    
      <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
      </filter>
      <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
    
      <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>  
      <session-config>
            <session-timeout>
                2
            </session-timeout>
        </session-config>
    
      <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!-- Actually the Dispatcher servlet should be appServlet-context.xml under WEB-INF.
        But we can override and specify the alternate location and specialized name, using init-param element tag -->
        <!-- init-param tag is used to initialize servlet initialization parameter specific to a particular servlet. 
        That is why used within an servlet. -->
        <init-param>
          <param-name>contextConfigLocation</param-name>
                <param-value>
                    classpath:/spring/appServlet/servlet-context.xml
                </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
      </servlet-mapping>  
    
    </web-app>
    

    我已经设置了这个项目,它在本地运行良好,但当我将其部署到prod时,我会遇到以下错误。顺便说一句,两者都在tomcat 8上运行。 我不认为spring与spring安全版本是另一个答案中建议的问题。 此外,我不习惯在服务/身份验证提供程序中使用@Service,因为它在localhost中工作。请帮忙。

    org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class org.springframewo
    rk.web.context.ContextLoaderListener
     org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.De
    faultSecurityFilterChain#0' while setting bean property 'sourceList' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springf
    ramework.security.web.DefaultSecurityFilterChain#0': Cannot resolve reference to bean 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' while setting constructor a
    rgument with key [5]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.UsernamePasswordAuthenti
    cationFilter#0': Cannot resolve reference to bean 'org.springframework.security.authentication.ProviderManager#0' while setting bean property 'authenticationManager'; nested exception is org.springframe
    work.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot resolve reference to bean 'org.springframework.security.co
    nfig.authentication.AuthenticationManagerFactoryBean#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'or
    g.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationEx
    ception: Error creating bean with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'myAuthenticationProvider' while setting constructor argument with key [0]; 
    nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.ct.www.provider.CustomAuthenticationProvider] for bean with name 'myAuthenticationProv
    ider' defined in class path resource [spring/appServlet/spring-security.xml]; nested exception is java.lang.ClassNotFoundException: com.ct.www.provider.CustomAuthenticationProvider
    

    堆栈跟踪非常大且嵌套,但最后一行解释了所有内容。

    enter image description here

    这是我的pom。xml

    <?xml version="1.0" encoding="UTF-8"?>
    
    <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/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.ct.www</groupId>
        <packaging>war</packaging>
        <version>1.0.0-BUILD-SNAPSHOT</version>
        <properties>
            <java-version>1.8</java-version>
            <org.springframework-version>4.0.3.RELEASE</org.springframework-version>
            <spring.security.version>4.0.1.RELEASE</spring.security.version>
            <apachetiles.version>3.0.8</apachetiles.version>
            <org.aspectj-version>1.7.4</org.aspectj-version>
            <org.slf4j-version>1.7.5</org.slf4j-version>
            <hibernate.version>4.3.5.Final</hibernate.version>
            <jackson.version>1.9.10</jackson.version>
        </properties>
        <dependencies>
            <!-- Spring -->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>${org.springframework-version}</version>
            <!--    <exclusions>
                    Exclude Commons Logging in favor of SLF4j
                    <exclusion>
                        <groupId>commons-logging</groupId>
                        <artifactId>commons-logging</artifactId>
                     </exclusion>
                </exclusions> -->
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
                <version>${org.springframework-version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-tx</artifactId>
                <version>${org.springframework-version}</version>
            </dependency>
                <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
         <!-- Apache Tiles -->
            <dependency>
                <groupId>org.apache.tiles</groupId>
                <artifactId>tiles-core</artifactId>
                <version>${apachetiles.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.tiles</groupId>
                <artifactId>tiles-api</artifactId>
                <version>${apachetiles.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.tiles</groupId>
                <artifactId>tiles-servlet</artifactId>
                <version>${apachetiles.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.tiles</groupId>
                <artifactId>tiles-jsp</artifactId>
                <version>${apachetiles.version}</version>
            </dependency>
    
            <!-- Jackson JSON Mapper -->
            <dependency>
                <groupId>org.codehaus.jackson</groupId>
                <artifactId>jackson-mapper-asl</artifactId>
                <version>${jackson.version}</version>
            </dependency>
    
            <dependency>
                <groupId>org.codehaus.jackson</groupId>
                <artifactId>jackson-core-asl</artifactId>
                <version>${jackson.version}</version>
            </dependency>
    
            <!-- Twilio -->
            <dependency>
                <groupId>com.twilio.sdk</groupId>
                <artifactId>twilio-java-sdk</artifactId>
                <version>4.1.0</version>
                <scope>compile</scope>
            </dependency>
    
            <!--  Spring Security  -->
            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-web</artifactId>
                <version>${spring.security.version}</version>
            </dependency>
                <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-core</artifactId>
                <version>${spring.security.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-config</artifactId>
                <version>${spring.security.version}</version>
            </dependency>
    
            <!-- Spring Security JSP Taglib -->
            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-taglibs</artifactId>
                <version>${spring.security.version}</version>
            </dependency>
    
    
            <!-- Hibernate -->
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
                <version>${hibernate.version}</version>
            </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
                <version>${hibernate.version}</version>
            </dependency>
    
            <!-- Apache Commons DBCP -->
            <dependency>
                <groupId>commons-dbcp</groupId>
                <artifactId>commons-dbcp</artifactId>
                <version>1.4</version>
            </dependency>
            <!-- Spring ORM -->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-orm</artifactId>
                <version>${org.springframework-version}</version>
            </dependency>
    
            <!-- AspectJ -->
            <dependency>
                <groupId>org.aspectj</groupId>
                <artifactId>aspectjrt</artifactId>
                <version>${org.aspectj-version}</version>
            </dependency>   
    
            <!-- Logging -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>${org.slf4j-version}</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>jcl-over-slf4j</artifactId>
                <version>${org.slf4j-version}</version>
                <scope>runtime</scope>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>${org.slf4j-version}</version>
                <scope>runtime</scope>
            </dependency>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.15</version>
                <exclusions>
                    <exclusion>
                        <groupId>javax.mail</groupId>
                        <artifactId>mail</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>javax.jms</groupId>
                        <artifactId>jms</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>com.sun.jdmk</groupId>
                        <artifactId>jmxtools</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>com.sun.jmx</groupId>
                        <artifactId>jmxri</artifactId>
                    </exclusion>
                </exclusions>
                <scope>runtime</scope>
            </dependency>
    
            <!-- @Inject -->
            <dependency>
                <groupId>javax.inject</groupId>
                <artifactId>javax.inject</artifactId>
                <version>1</version>
            </dependency>
    
            <!-- Servlet -->
           <!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>3.0-alpha-1</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet.jsp</groupId>
                <artifactId>jsp-api</artifactId>
                <version>2.1</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jstl</artifactId>
                <version>1.2</version>
            </dependency>
    
            <!-- Test -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.7</version>
                <scope>test</scope>
            </dependency>
    
            <!-- MySQL -->
             <!-- MySQL database driver -->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.35</version>
            </dependency>
    
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-eclipse-plugin</artifactId>
                    <version>2.9</version>
                    <configuration>
                        <additionalProjectnatures>
                            <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                        </additionalProjectnatures>
                        <additionalBuildcommands>
                            <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                        </additionalBuildcommands>
                        <downloadSources>true</downloadSources>
                        <downloadJavadocs>true</downloadJavadocs>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.5.1</version>
                    <configuration>                 
                        <source>1.8</source>
                        <target>1.8</target>
                        <compilerArgument>-Xlint:all</compilerArgument>
                        <showWarnings>true</showWarnings>
                        <showDeprecation>true</showDeprecation>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>              
                    <configuration>                 
                      <webXml>WebContent/WEB-INF/web.xml</webXml>                   
                    </configuration>
                </plugin> 
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.2.1</version>
                    <configuration>
                        <mainClass>org.test.int1.Main</mainClass>
                    </configuration>
                </plugin>
            </plugins>
            <finalName>${project.artifactId}</finalName>
        </build>
        <artifactId>ct</artifactId>
        <name>ct</name>
    </project>
    

    我正在建立目录 pom.xml 通过使用 mvn clean install -DskipTests 并将战争上传到prod中的tomcat8。

    我在pom中遇到了这个错误。xml

    [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ --- [INFO] No sources to compile
    

    然后我把它更新到了3.3,那就不见了。但我仍然得到ClassNotFoundException异常,当我提取它时,我在我的war中没有看到java类。

    2 回复  |  直到 6 年前
        1
  •  1
  •   Konstantin Pribluda    6 年前

    这就是com。计算机断层扫描。www.provider。生产环境中缺少CustomAuthenticationProvider。(以及您的生产工件)。您的本地服务器可能来自其他类加载器-同时仔细检查您的构建环境和IDE设置

        2
  •  0
  •   sofs1 Romain Manni-Bucau    6 年前

    好啊问题是因为我的pom。xml没有将类文件和其他xml文件包含到已构建的最终war中。

    这解决了我的问题。 https://stackoverflow.com/a/49123071/3705478