小编ima*_*ban的帖子

带有片段和FragmentActivity的TabHost

我正在研究Android应用程序,我想使用3个选项卡为每个选项卡使用Fragments进行导航,但我不知道如何创建这样做的结构.

我想分别添加每个片段,因为每个片段都不同,但我不知道在FragmentActivity中将它们添加到何处.

我有这些文件.

tabs_layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <TabHost android:id="@android:id/tabhost"
         android:layout_width="match_parent"
         android:layout_height="match_parent">

         <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

             <TabWidget
                android:id="@android:id/tabs" 
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
             />

             <FrameLayout
                 android:id="@android:id/tabcontent" 
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"

             >

                 <FrameLayout
                     android:id="@+id/tabRateAPet" 
                     android:layout_width="match_parent"
                     android:layout_height="match_parent"

                 />

                 <FrameLayout
                     android:id="@+id/tabViewMyRates" 
                     android:layout_width="match_parent"
                     android:layout_height="match_parent"

                 />

                 <FrameLayout
                     android:id="@+id/tabViewGlobalRates" 
                     android:layout_width="match_parent"
                     android:layout_height="match_parent"

                 />


             </FrameLayout>
        </LinearLayout>
    </TabHost>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

TabsMain.java

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;

public class MainTabsActivity extends FragmentActivity {
public static final String RATE_A_PET = "Rate a Pet";
public static final String MY_RATES = "My Rates";
public static final …
Run Code Online (Sandbox Code Playgroud)

android android-tabhost android-fragments android-fragmentactivity

30
推荐指数
1
解决办法
10万
查看次数

Spring Security + Basic Auth + API返回404而不是401

我有一个使用基本身份验证以Spring Security运行的Spring Boot应用程序。提供正确的基本身份验证凭据后,将调用控制器方法,但是对于不正确的身份验证凭据,我收到的是404 Not Found而不是401 Unauthorized。

这是我的Spring Security Config

@Configuration
public static class ApiSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http
            .antMatcher("/useradmin/api")
            .authorizeRequests()
                .anyRequest().authenticated()
                .and()
            .httpBasic().authenticationEntryPoint(authenticationEntryPoint()).and().csrf().disable();

    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .withUser("default").password("password").roles("USER");
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经用无效的凭据将基本身份验证重定向到/ error审查了Spring Security,并且如果我ErrorMvcAutoConfiguration.class从自动配置类中排除,则会得到401。但是,如果我将其保留为自动配置,则只会得到404,实际上它没有/error像前面提到的问题一样被重定向到说。

我创建了自己的实现BasicErrorController,我在getError方法上设置了一个断点,但从未实现过此点,因此我认为有其他事情正在捕获响应并将其状态从401更改为404。

还有什么可能是这个问题的根源?

spring-mvc spring-security basic-authentication

5
推荐指数
0
解决办法
853
查看次数