Uploaded image for project: 'Shiro'
  1. Shiro
  2. SHIRO-635

confilict with spring-boot-starter-data-jpa

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.4.0-RC2
    • Fix Version/s: None
    • Component/s: Integration: Spring
    • Labels:
      None
    • Environment:
      win10, intellij idea
    • Flags:
      Important

      Description

      i am using the shiro-spring-boot-web-starter:1.4.0 with spring boot.
      the attachment is a maven based project.
      the example class is com.ankin.dajucheng.controller.ClassificationController.
      when spring-data-jpa is used, the method:queryClassifications in the controller class of spring mvc can not mapping to the correct method, if you enter 'http://localhost:8500/classification/simple', it will return 404.
      But if i remove the shiro annotations(@RequiresRoles) in the controller class, then if you enter 'http://localhost:8500/classification/simple', it will return the correct string 'simple:success';
      the datasource is set to jdbc:mysql://192.168.1.118:3306/nmx in application.properties, you can change to any mysql database url. i haven't add any entity, so every avaliable database is ok.

      public class JpaRealm extends AuthorizingRealm {

      @Override
      protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection)

      { String username = (String) principalCollection.getPrimaryPrincipal(); SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo(); return authorizationInfo; }

      @Override
      protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException

      { String username = (String) authenticationToken.getPrincipal(); SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo( username, authenticationToken.getPrincipal(), null, getName() ); return authenticationInfo; }

      }

      @RestController
      @RequestMapping("/classification")
      public class ClassificationController {

      private static final Logger logger = LoggerFactory.getLogger(ClassificationController.class);

      @RequestMapping(value = "/simple", method = RequestMethod.GET)
      public String queryClassifications(@RequestParam(name = "id", defaultValue = "0") Integer parentId)

      { return "simple:success"; }

      @RequiresRoles("ADMIN")
      @RequestMapping(method = RequestMethod.POST)
      @ResponseStatus(HttpStatus.CREATED)
      public String saveClassification(String classification)

      { return null; }

      @RequiresRoles("ADMIN")
      @RequestMapping(method = RequestMethod.PUT)
      public String updateClassification(String classification) { return null; }

      }

      @SpringBootApplication(exclude = ErrorMvcAutoConfiguration.class)
      public class DajuchengApplication extends SpringBootServletInitializer {

      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder builder)

      { return configureApplication(builder); }

      public static void main(String[] args)

      { configureApplication(new SpringApplicationBuilder()).run(args); }

      private static SpringApplicationBuilder configureApplication(SpringApplicationBuilder builder)

      { return builder.sources(DajuchengApplication.class).bannerMode(Banner.Mode.OFF); }

      @Bean
      public Realm realm()

      { return new JpaRealm(); }

      @Bean
      public ShiroFilterChainDefinition shiroFilterChainDefinition()

      { DefaultShiroFilterChainDefinition chainDefinition = new DefaultShiroFilterChainDefinition(); chainDefinition.addPathDefinition("/**", "anon"); return chainDefinition; }

      }

      debug=false
      server.port=8500
      server.context-path=/
      server.tomcat.uri-encoding=UTF-8
      server.session.timeout=43200
      spring.http.encoding.charset=UTF-8
      spring.http.encoding.force=true

      #spring-boot-data-jpa\u9ED8\u8BA4\u4E3A\u4E0B\u5212\u7EBF, \u8FD9\u91CC\u6539\u4E3A\u4E0E\u6570\u636E\u5E93\u5B57\u6BB5\u5B8C\u5168\u4E00\u81F4
      spring.jpa.open-in-view=false
      spring.jpa.hibernate.ddl-auto=none
      spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

      shiro.loginUrl=/dispatch.jsp
      shiro.unauthorizedUrl=/unauthorized.jsp

      spring.datasource.driver-class-name=com.mysql.jdbc.Driver
      #spring.datasource.type=com.zaxxer.hikari.HikariDataSource
      spring.datasource.url=jdbc:mysql://192.168.1.118:3306/nmx?useSSL=false&useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true&useServerPrepStmts=true&cachePrepStmts=true&cacheCallableStmts=true&prepStmtCacheSize=250&prepStmtCacheSqlLimit=1024&useConfigs=maxPerformance
      spring.datasource.username=ankin
      spring.datasource.password=anKins10#410

      <dependencies>
      <dependency>
      <groupId>org.apache.shiro</groupId>
      <artifactId>shiro-spring-boot-web-starter</artifactId>
      <version>1.4.0</version>
      </dependency>

      <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
      </dependency>

      <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      </dependency>

      <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <scope>runtime</scope>
      </dependency>
      <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <scope>runtime</scope>
      </dependency>
      <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-configuration-processor</artifactId>
      <optional>true</optional>
      </dependency>
      <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      <!-<scope>provided</scope>->
      </dependency>
      <dependency>
      <groupId>org.apache.tomcat.embed</groupId>
      <artifactId>tomcat-embed-jasper</artifactId>
      <!-<scope>provided</scope>->
      </dependency>

      <!-test start->
      <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
      </dependency>
      <dependency>
      <groupId>org.springframework.restdocs</groupId>
      <artifactId>spring-restdocs-mockmvc</artifactId>
      <scope>test</scope>
      </dependency>
      <!-test end->
      </dependencies>

        Attachments

        1. xiaojucheng.7z
          3 kB
          gejian

          Activity

            People

            • Assignee:
              lhazlewood Les Hazlewood
              Reporter:
              gj gejian
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:

                Time Tracking

                Estimated:
                Original Estimate - 1h 1m
                1h 1m
                Remaining:
                Remaining Estimate - 1h 1m
                1h 1m
                Logged:
                Time Spent - Not Specified
                Not Specified