Rectangle 27 60

I think that the reason of your problem can be in that your xml configuration file for spring security isn't loaded when you start your web app.

To fix this you should specify all your XML config files in web.xml like that:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring-security.xml, /WEB-INF/applicationContext.xml</param-value>
</context-param>

If you have your config files in classpath (not WEB-INF folder or it's subfolders) then you can specify list of config files in such way;

...
<param-value>
    classpath:applicationContext.xml,
    classpath:spitter-security.xml
</param-value>
...
<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

but I have context-parameter and listener configuration in web.xml

yeah this is the problem with my context-parameter. I have given parameter value as classpath*:*-context.xml which is not correct way to pick up security-context.xml. So changed wildcard to classpath:**/*-context.xml. Now everything working fine

Note: I had to add it to the root application context (not the app servlet context).

@dimas I have a similar problem. Are you willing to help me out with it? Here is the link: stackoverflow.com/questions/22643577/

spring - getting exception: No bean named 'springSecurityFilterChain' ...

spring spring-mvc spring-security
Rectangle 27 9

I just added the bean definition in applicationContext.xml as Spring asked:

<bean id="springSecurityFilterChain" class="org.springframework.web.filter.DelegatingFilterProxy"/>

spring - getting exception: No bean named 'springSecurityFilterChain' ...

spring spring-mvc spring-security
Rectangle 27 5

Make sure that the security xml is loaded by the ContextLoaderListener and not the DispatcherServlet. The DelegatingFilterProxy will only look into the root applicationcontext (which is loaded by the ContextLoaderListener) for the bean to delegate to. (see spring's documentation here)

In case you only have one dispatcher servlet, you can define your application context globally and leave the dispatcher servlet parameter empty.

<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml,
                     /WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </context-param>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>mmasgisServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value></param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

spring - No bean named springSecurityFilterChain is defined - Stack Ov...

spring spring-mvc spring-security
Rectangle 27 3

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/root-context.xml, /WEB-INF/spring-security.xml</param-value>
</context-param>

<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

        <!-- filter declaration for Spring Security -->
<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>

spring - getting exception: No bean named 'springSecurityFilterChain' ...

spring spring-mvc spring-security
Rectangle 27 2

Most likely you're missing the <http> element from your configuration. You'll need to create a minimal configuration for Spring Security, using the security namespace:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:sec="http://www.springframework.org/schema/security"
    xsi:schemaLocation="
      http://www.springframework.org/schema/security
      http://www.springframework.org/schema/security/spring-security-3.1.xsd
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">

    <http auto-config='true'>
        <intercept-url pattern="/**" access="ROLE_USER" />
    </http>

</beans:beans>

Also - your XML configuration - if that is a single file, then you don't need to declare the <beans xmlns... element twice.

What's the Java configuration equivalent?

spring - No bean named springSecurityFilterChain is defined - Stack Ov...

spring spring-mvc spring-security
Rectangle 27 2

I'm not sure if the web.xml you have given is complete but you must have at least the following in that file:

<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>

After that, I think you need at least 1 http configuration in your root-context.xml file (I'm not sure about this):

<http auto-config='true'>
    <intercept-url pattern="/**" access="ROLE_USER" />
  </http>

spring - No bean named springSecurityFilterChain is defined - Stack Ov...

spring spring-mvc spring-security
Rectangle 27 1

You haven't included your security config file hence the issue.

Change the following line:

@Override
    protected Class<?>[] getServletConfigClasses() {
        // TODO Auto-generated method stub
        return new Class<?>[] {WebConfig.class, SecurityConfig.class};
    }

If not let me know and i'll review further

Yea that's because you are not calling the SecurityConfig class which contains your ComponentScan. If you add the class as listed you won't need to duplicate the ComponentScan. is your code actually making a call to authenticate at all?

spring security with java config , No bean named 'springSecurityFilter...

java spring spring-mvc spring-security
Rectangle 27 1

<context:annotation-config/>
<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/security
    http://www.springframework.org/schema/security/spring-security.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd">

    <beans:bean class="com.mkyong.web.controller.SecurityConfig">
    <context:annotation-config/>   
</beans:beans>
<web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Spring MVC Application</display-name>
    <!-- Spring MVC -->
    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


    <!-- START UPDATES -->
    <context-param>
        <param-name>contextClass</param-name>
        <param-value>
            org.springframework.web.context.support.AnnotationConfigWebApplicationContext
        </param-value>
    </context-param>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>com.mkyong.web.controller.SecurityConfig</param-value>
    </context-param>  
    <!-- END UPDATES -->


    <!-- Spring Security -->
    <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>
</web-app>

java - Spring Security - No bean named 'springSecurityFilterChain' is ...

java spring spring-mvc spring-security
Rectangle 27 1

The problem was solved by replacing

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/someXmlfile.xml</param-value>
    </context-param>

with

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        com.portal.configuration.IntegrationServerWebConfig
    </param-value>
</context-param>
@Configuration

@ImportResource({
    "classpath:/WEB-INF/mvc-dispatcher-servlet.xml",
    "classpath:/WEB-INF/spring-servlet.xml"})

@ComponentScan(basePackages = {"com.portal"})
public class IntegrationServerWebConfig {
}

java - Spring security No bean named 'CustomAuthenticationProvider' is...

java spring spring-security
Rectangle 27 57

Spring Data JPA by default looks for an EntityManagerFactory named entityManagerFactory. Check out this part of the Javadoc of EnableJpaRepositories or Table 2.1 of the Spring Data JPA documentation.

emf
entityManagerFactory
<jpa:repositories base-package="your.package" entity-manager-factory-ref="emf" />

(if you are using XML)

@EnableJpaRepositories(basePackages="your.package", entityManagerFactoryRef="emf")

(if you are using Java Config)

Great answer. Just a minor correction, it should be: "entity-manager-factory-ref" not "entity-manager-ref"

java - Spring data jpa- No bean named 'entityManagerFactory' is define...

java spring-mvc jpa spring-data spring-data-jpa
Rectangle 27 3

<param-value>
        /WEB-INF/applicationContext.xml
        /WEB-INF/applicationContext-security.xml
 </param-value>

to do the following in /WEB-INF/applicationContext.xml:

<import resource="applicationContext-security.xml"/>

Thank you slavov but the issue is resolved long back!!

spring mvc - org.springframework.beans.factory.NoSuchBeanDefinitionExc...

spring-mvc spring-security
Rectangle 27 3

About the issue with thecontroller: you actually don't have a mapping for /extjs-crud-grid-spring-hibernate/main.action

What you are mapping in that controller is, for example: /extjs-crud-grid-spring-hibernate/contact/main.action

If you need to access the first URI you should remove "contact" from the controller and only map it with "/main.action".

About Spring Security, i'm sure that this tutorial is useful (or almost any that you can find googling), but if you really want to learn about it, i strongly recommend the Spring books: Spring recipes and Spring Security 3.

spring mvc - org.springframework.beans.factory.NoSuchBeanDefinitionExc...

spring-mvc spring-security
Rectangle 27 5

Spring container is trying to find springSecurityFilterChain bean in application context, not web application context. Change spring security configuration to be included in root context.

Please provide more details as to how you think this problem can be resolved. ie specifically where in what files should the definition for the filter go? Thanks

No. I have never been able to resolve the issue. Still struggling with that.

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

spring - org.springframework.beans.factory.NoSuchBeanDefinitionExcepti...

java spring spring-mvc spring-security
Rectangle 27 5

WebSocket Security is for the STOMP sub-protocol and relies on the STOMP Broker Configuration.

@EnableWebSocket
@EnableWebSocketMessageBroker
AbstractSecurityWebSocketMessageBrokerConfigurer

You don't need WebSocketConfigurer in that case, by the way.

spring websocket with spring security start failed with "No bean named...

spring spring-security spring-boot spring-websocket
Rectangle 27 8

In your application context, change the bean with id from emf to entityManagerFactory:

<bean id="emf"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="packagesToScan" value="org.wahid.cse.entity" />
    <property name="dataSource" ref="dataSource" />

    <property name="jpaProperties">
        <props>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.hbm2ddl.auto">create</prop>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
        </props>
    </property>

    <property name="persistenceProvider">
        <bean class="org.hibernate.jpa.HibernatePersistenceProvider"></bean>
    </property>

</bean>
<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="packagesToScan" value="org.wahid.cse.entity" />
    <property name="dataSource" ref="dataSource" />

    <property name="jpaProperties">
        <props>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.hbm2ddl.auto">create</prop>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
        </props>
    </property>

    <property name="persistenceProvider">
        <bean class="org.hibernate.jpa.HibernatePersistenceProvider"></bean>
    </property>

</bean>

Thanks. You solved my problem by following "In your application context, change the bean with id from emf to entityManagerFactory". Regards.

What we can use for Annotation based example? I'm facing extact issue

@javaHelper Look at geoand's answer above. He has shown one of the ways to fix the issue for Java config. If you are still unclear or face an issue, ask a new question and I can help you with it by providing the appropriate code (difficult to do that in a comment).

java - Spring data jpa- No bean named 'entityManagerFactory' is define...

java spring-mvc jpa spring-data spring-data-jpa
Rectangle 27 1

I was getting same issue. I tried security:intercept-url pattern="/**" access="ROLE_USER"

Remove criteria on pattern, my problem has been solved. Spring security itself append /spring_security_login url and provide it's login page.

The issue was resolved earlier and I had accepted an answer then.I believe your may help others running into the issue.Thank you for the response

spring mvc - org.springframework.beans.factory.NoSuchBeanDefinitionExc...

spring-mvc spring-security
Rectangle 27 2

The applicationContext file is likely not on the class path; I'm not sure that the all_URL_prefix will dig past the root level of the filesystem and jars, making the test go wonky. Try moving the config file, or changing the list of locations from which to grab the config file.

You are brilliant Dave, glad I can learn from the experts here on stackoverflow. ClassPathXmlApplicationContext("META-INF/spring/applicationContext.xml") does the trick. Tried this solution earlier, but assumed the root directory was META-INF, so obviously it didn't work.

Not brilliant, just been slammed by the same types of errors ;)

spring - No bean named 'errorNotifier' is defined - Stack Overflow

spring spring-roo
Rectangle 27 2

public class MyRepositoryImpl extends JdbcDaoSupport implements MyRepository {

    @Qualifier("odsDataSource")
    @Autowired(required = true)
    private DataSource ds;

    public MyRepositoryImpl() {
    }

    @PostConstruct
    void postConstruct() {
        setDataSource(ds);
    }

    ...
}

If you develop your repositories by extending JdbcDaoSupport (and also a few other Spring-provided helpers), then they will default to attempting to wire by name on the default "entityManagerFactory". So you need to initialise them by injecting your alternatively-named data beans.

Another possibility assuming you are using JPA.

@Repository
public class MyRepositoryImpl implements MyRepository {
    @PersistenceContext(unitName="MyPersistenceUnit")
    private EntityManager entityManager;

    public List<MyModel> findAll() {
        return entityManager.createNamedQuery("MyModel.findAll").getResultList();
    }
}

Update: For folks coming across this issue more recently, using Spring Boot and Spring Data JPA, I wrote a blog post running through the essentials of getting that working: http://scattercode.co.uk/2016/01/05/multiple-databases-with-spring-boot-and-spring-data-jpa/

Can we have one custom repository and extend into all my repositories, so as to avoid writing implementation classes for all repositories. I added some code in my post to have custom repository. I am not sure if I am doing it correct way.

I'd say try using the @PersistenceContext annotation on your repository interface. I can't find any docs on it though, so I can't guarantee anything. :-/

unfortunately it does not work, I tried it yesterday.

Did you find the solution please? I'v exactly the same problem. Thank you.

I do now have a solution I could add, using Spring Data JPA if that's what you mean...

Spring Java Configuration No bean named 'entityManagerFactory' is defi...

spring configuration spring-data entitymanager spring-data-jpa
Rectangle 27 2

The @EnableMongoRepositories annotation will trigger creation of repository beans on startup, but you still need to register a MongoDB connection and create the MongoTemplate instance that is injected into these repositories. See the Spring Data MongoDB documentation. Here is an example:

@Configuration
@PropertySource({ "classpath:mongodb-data-source.properties" })
public class MongodbDataSourceConfig extends AbstractMongoConfiguration {

    @Autowired Environment env;

    @Override
    public String getDatabaseName(){
        return env.getRequiredProperty("mongo.name");
    }

    @Override
    @Bean
    public Mongo mongo() throws Exception {

        ServerAddress serverAddress = new ServerAddress(env.getRequiredProperty("mongo.host"));
        List<MongoCredential> credentials = new ArrayList<>();
        credentials.add(MongoCredential.createScramSha1Credential(
                env.getRequiredProperty("mongo.username"),
                env.getRequiredProperty("mongo.name"),
                env.getRequiredProperty("mongo.password").toCharArray()
        ));
        MongoClientOptions options = new MongoClientOptions.Builder()
            .build();
        return new MongoClient(serverAddress, credentials, options);
    }

}

java - spring data mongo - No bean named 'mongoTemplate' is defined - ...

java spring mongodb spring-data spring-data-mongodb
Rectangle 27 1

classpath*:/servlet-context.xml

/myproject/WebContent/WEB-INF/spring/appServlet/servlet-context.xml, however, isn't on the classpath root at all, and so Spring will ignore your file and build an empty context.

servlet-context.xml
WEB-INF/classes
WEB-INF/classes/servlet-context.xml
WEB-INF/classes/spring/appServlet/servlet-context.xml
classpath*:/spring/appServlet/servlet-context.xml

spring - no bean named "userDao" is defined - Stack Overflow

spring javabeans applicationcontext