Wiciaq123
Wiciaq123

Reputation: 515

Overriding Spring controller mapping

I have such a problem that I work on project where some parts are taken from legacy code which is already in JAR files. There are already some Spring controllers imported from those JAR files. I want to Override mapping in those imported controllers by extending those classes and creating/writing new methods. Unfortunately, I can not create new mapping because I don't know how many places old mapping appears and looking threw whole system is not possible. As I want to add some new functionality on the same mapping I tried with excluding old(imported) controller and also excluding configuration file which was importing that old controller using:

@ComponentScan.Filter(type = FilterType.REGEX)

Spring came back with problem of duplicated mapping and didn't allow me to deploy application properly.

Is there any option to exclude controller from application or check in which places controller bean is injected into application and override it?

Upvotes: 1

Views: 1253

Answers (1)

Sundararaj Govindasamy
Sundararaj Govindasamy

Reputation: 8495

You can exclude a class or package from Spring component scanning as below.

@Configuration
@ComponentScan(            
        excludeFilters = {
                @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.aaa.bbb.*"),
                @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = MyClassToExclude.class) })

By this way, you can exclude your legacy classes.

Upvotes: 2

Related Questions